/// <summary> /// Creates a new directory read task. /// </summary> /// <param name="path">The path of the directory to read.</param> /// <param name="builder">The builder to read to.</param> public ReadDirectory(string path, IForwardOnlyBuilder builder) : base(path) { _builder = builder ?? throw new ArgumentNullException(nameof(builder)); string manifestPath = Path.Combine(path, Manifest.ManifestFile); bool ShouldReadManifest() { try { // Symlinks and executable bits may be lost on non-Unix filesystems and can be reconstructed from a manifest file return(!FileUtils.IsUnixFS(Path.Combine(path, ".."))); } catch (Exception ex) when(ex is IOException or UnauthorizedAccessException) { return(true); } } if (File.Exists(manifestPath) && ShouldReadManifest()) { _manifest = Manifest.Load(manifestPath, ManifestFormat.Sha1New); } }
protected override void AddElements(IForwardOnlyBuilder builder) { builder.AddFile("normal", TestFile.DefaultContents.ToStream(), TestFile.DefaultLastWrite); builder.AddFile("executable", TestFile.DefaultContents.ToStream(), TestFile.DefaultLastWrite, executable: true); builder.AddSymlink("symlink", target: "abc"); builder.AddDirectory("dir"); builder.AddFile(Path.Combine("dir", "sub"), TestFile.DefaultContents.ToStream(), TestFile.DefaultLastWrite); }
protected abstract void AddElements(IForwardOnlyBuilder builder);