Beispiel #1
0
            /**
             * Adds an entry to the layer. If the source file is a directory, the directory and its contents
             * will be added recursively.
             *
             * @param sourceFile the source file to add to the layer recursively
             * @param pathInContainer the path in the container file system corresponding to the {@code
             *     sourceFile}
             * @param filePermissionProvider a provider that takes a source path and destination path on the
             *     container and returns the file permissions that should be set for that path
             * @param lastModifiedTimeProvider a provider that takes a source path and destination path on
             *     the container and returns the file modification time that should be set for that path
             * @return this
             * @throws IOException if an exception occurred when recursively listing the directory
             */
            public Builder AddEntryRecursive(
                SystemPath sourceFile,
                AbsoluteUnixPath pathInContainer,
                Func <SystemPath, AbsoluteUnixPath, FilePermissions> filePermissionProvider,
                Func <SystemPath, AbsoluteUnixPath, Instant> lastModifiedTimeProvider)
            {
                FilePermissions permissions  = filePermissionProvider?.Invoke(sourceFile, pathInContainer);
                Instant         modifiedTime = lastModifiedTimeProvider(sourceFile, pathInContainer);

                AddEntry(sourceFile, pathInContainer, permissions, modifiedTime);
                if (!Files.IsDirectory(sourceFile))
                {
                    return(this);
                }
                IEnumerable <SystemPath> files = Files.List(sourceFile);

                {
                    foreach (SystemPath file in files.ToList())
                    {
                        AddEntryRecursive(
                            file,
                            pathInContainer.Resolve(file.GetFileName()),
                            filePermissionProvider,
                            lastModifiedTimeProvider);
                    }
                }
                return(this);
            }
Beispiel #2
0
        /**
         * Adds a new layer to the container with {@code files} as the source files and {@code
         * pathInContainer} as the path to copy the source files to in the container file system.
         *
         * <p>Source files that are directories will be recursively copied. For example, if the source
         * files are:
         *
         * <ul>
         *   <li>{@code fileA}
         *   <li>{@code fileB}
         *   <li>{@code directory/}
         * </ul>
         *
         * and the destination to copy to is {@code /path/in/container}, then the new layer will have the
         * following entries for the container file system:
         *
         * <ul>
         *   <li>{@code /path/in/container/fileA}
         *   <li>{@code /path/in/container/fileB}
         *   <li>{@code /path/in/container/directory/}
         *   <li>{@code /path/in/container/directory/...} (all contents of {@code directory/})
         * </ul>
         *
         * @param files the source files to copy to a new layer in the container
         * @param pathInContainer the path in the container file system corresponding to the {@code
         *     sourceFile}
         * @return this
         * @throws IOException if an exception occurred when recursively listing any directories
         */
        public FibContainerBuilder AddLayer(IList <SystemPath> files, AbsoluteUnixPath pathInContainer)
        {
            pathInContainer = pathInContainer ?? throw new ArgumentNullException(nameof(pathInContainer));
            files           = files ?? throw new ArgumentNullException(nameof(files));

            LayerConfiguration.Builder layerConfigurationBuilder = LayerConfiguration.CreateBuilder();

            foreach (SystemPath file in files)

            {
                layerConfigurationBuilder.AddEntryRecursive(
                    file, pathInContainer.Resolve(file.GetFileName()));
            }

            return(AddLayer(layerConfigurationBuilder.Build()));
        }