public IFile LinkFrom(FileInfo source, string linkName, bool overwrite) { this.CheckDeleted(); string dest = Path.GetFileName(linkName); if (!Directory.IsValidFileName(dest)) { throw new DirectoryNotFoundException($"Filename {dest} is invalid."); } if (!source.ContentExists()) { throw new FileNotFoundException($"{source.FullName} could not be found."); } if (this.ContainsFile(dest) && !overwrite) { throw new IOException($"{source.Name} already exists in the target directory"); } var linkPath = this.ThisDirectory.Path / dest; FileSystem.CreateSymbolicLink(source.FullName, this.RootFileSystem.ConvertPathToInternal(linkPath), FileType.File); // todo GUID semantics (not necessary for tsuku but maybe for db-backed?) return(this.OpenFile(dest)); }
public IFile MoveFrom(IFile source, string targetName, bool overwrite) { this.CheckDeleted(); #pragma warning disable CS0618 // Type or member is obsolete string dest = Path.GetFileName(targetName); if (!Directory.IsValidFileName(dest)) { throw new DirectoryNotFoundException($"Filename {dest} is invalid."); } if (!source.Created) { throw new FileNotFoundException($"{source.UnsafeGetPath().FullName} could not be found."); } if (this.ContainsFile(dest) && !overwrite) { throw new IOException($"{source.Name} already exists in the target directory"); } // Preserve GUID if (!this.FileGuidProvider.TryGetGuid(source.UnsafeGetPath(), out Guid existingGuid)) { existingGuid = Guid.NewGuid(); } var file = this.OpenFile(dest, existingGuid); // unsafe usage here as optimization. source.UnsafeGetPath() .MoveTo(file.UnsafeGetPath().ToString(), overwrite); #pragma warning restore CS0618 // Type or member is obsolete source.Delete(); return(this.OpenFile(dest)); }
public async Task <IFile> CopyFromAsync(FileInfo source, string targetName, bool overwrite, CancellationToken cancellation = default) { this.CheckDeleted(); if (!source.ContentExists()) { throw new FileNotFoundException($"{source.FullName} could not be found."); } string?fileName = Path.GetFileName(targetName); if (!Directory.IsValidFileName(fileName)) { throw new DirectoryNotFoundException($"The filename {targetName} is invalid."); } // Preserve GUID if (!this.FileGuidProvider.TryGetGuid(source, out Guid existingGuid)) { existingGuid = Guid.NewGuid(); } var file = this.OpenFile(fileName, existingGuid); if (file.Created && !overwrite) { throw new IOException($"{source.Name} already exists in the target directory."); } using (var newStream = file.OpenStream(FileMode.Create, FileAccess.ReadWrite)) using (var sourceStream = source.OpenRead()) { await sourceStream.CopyToAsync(newStream, cancellation); } return(file); }
public IDeletableDirectory LinkFrom(DirectoryInfo source, string linkName, bool overwrite) { this.CheckDeleted(); string dest = Path.GetFileName(linkName); if (!Directory.IsValidFileName(dest)) { throw new DirectoryNotFoundException($"Filename {dest} is invalid."); } if (!source.ContentExists()) { throw new DirectoryNotFoundException($"{source.FullName} could not be found."); } if (this.ContainsFile(dest) && !overwrite) { throw new IOException($"{source.Name} already exists in the target directory"); } var linkPath = this.ThisDirectory.Path / dest; FileSystem.CreateSymbolicLink(source.FullName, this.RootFileSystem.ConvertPathToInternal(linkPath), FileType.Directory); return(this.OpenDirectory(dest)); }
public IFile CopyFrom(FileInfo source, string targetName, bool overwrite) { this.CheckDeleted(); if (!source.ContentExists()) { throw new FileNotFoundException($"{source.FullName} could not be found."); } string?fileName = Path.GetFileName(targetName); if (!Directory.IsValidFileName(fileName)) { throw new DirectoryNotFoundException($"Filename {targetName} is invalid."); } source.CopyTo(this.RootFileSystem.ConvertPathToInternal(this.ThisDirectory.Path / fileName), overwrite); // Preserve GUID, on Linux xattrs are not preserved from copy. if (!this.FileGuidProvider.TryGetGuid(source, out Guid existingGuid)) { existingGuid = Guid.NewGuid(); } return(this.OpenFile(fileName, existingGuid)); }