예제 #1
0
            /**
             * Adds a {@link TarArchiveEntry} if its extraction path does not exist yet. Also adds all of
             * the parent directories on the extraction path, if the parent does not exist. Parent will have
             * modified time to set to {@link LayerConfiguration#DEFAULT_MODIFIED_TIME}.
             *
             * @param tarArchiveEntry the {@link TarArchiveEntry}
             */
            public void Add(TarEntry tarArchiveEntry)
            {
                if (names.Contains(tarArchiveEntry.Name))
                {
                    return;
                }

                // Adds all directories along extraction paths to explicitly set permissions for those
                // directories.
                SystemPath namePath = Paths.Get(tarArchiveEntry.Name);

                if (namePath.GetParent() != namePath.GetRoot())
                {
                    TarEntry dir = TarEntry.CreateTarEntry(namePath.GetParent().ToString().Replace(Path.DirectorySeparatorChar, '/'));
                    dir.Name           += "/";
                    dir.ModTime         = DateTimeOffset.FromUnixTimeMilliseconds(LayerConfiguration.DefaultModifiedTime.ToUnixTimeMilliseconds()).DateTime;
                    dir.TarHeader.Mode &= ~(int)PosixFilePermissions.All;
                    dir.TarHeader.Mode |= (int)(
                        PosixFilePermissions.OwnerAll
                        | PosixFilePermissions.GroupReadExecute
                        | PosixFilePermissions.OthersReadExecute);
                    dir.TarHeader.TypeFlag = TarHeader.LF_DIR;
                    Add(dir);
                }

                entries.Add(tarArchiveEntry);
                names.Add(tarArchiveEntry.Name);
            }
예제 #2
0
        /**
         * Resolves this path against another relative path (by the name elements of {@code
         * relativePath}).
         *
         * @param relativePath the relative path to resolve against
         * @return a new {@link AbsoluteUnixPath} representing the resolved path
         */
        public AbsoluteUnixPath Resolve(SystemPath relativePath)
        {
            relativePath = relativePath ?? throw new ArgumentNullException(nameof(relativePath));
            Preconditions.CheckArgument(
                relativePath.GetRoot() == null, "Cannot resolve against absolute Path: " + relativePath);

            return(AbsoluteUnixPath.FromPath(Paths.Get(unixPath).Resolve(relativePath)));
        }
예제 #3
0
        /**
         * Gets a new {@link AbsoluteUnixPath} from a {@link Path}. The {@code path} must be absolute
         * (indicated by a non-null {@link Path#getRoot}).
         *
         * @param path the absolute {@link Path} to convert to an {@link AbsoluteUnixPath}.
         * @return a new {@link AbsoluteUnixPath}
         */
        public static AbsoluteUnixPath FromPath(SystemPath path)
        {
            path = path ?? throw new ArgumentNullException(nameof(path));
            if (path.GetRoot() == null)
            {
                path = SystemPath.From(Path.GetFullPath(path));
            }
            Preconditions.CheckArgument(
                path?.GetRoot() != null, "Cannot create AbsoluteUnixPath from non-absolute Path: " + path);

            ImmutableArray <string> .Builder pathComponents =
                ImmutableArray.CreateBuilder <string>();
            foreach (SystemPath pathComponent in path)
            {
                pathComponents.Add(pathComponent.ToString());
            }
            return(new AbsoluteUnixPath(pathComponents.ToImmutable(), path.GetRoot()));
        }