public async Task UnlinkAsync(IUnixFileSystemEntry entry, CancellationToken cancellationToken) { if (entry is GcsFileEntry gcsFileEntry) { try { await _storageClient.DeleteObjectAsync(_bucketName, gcsFileEntry.FullName, null, cancellationToken); } catch { } } else if (entry is GcsDirectoryEntry gcsDirectoryEntry) { var foldersToDelete = new ConcurrentBag <GcsDirectoryEntry>(); await UnlinkDirectoriesRecursivelyAsync(gcsDirectoryEntry, cancellationToken, foldersToDelete); var reversed = foldersToDelete.Reverse(); foreach (var folderToDelete in reversed) { try { await _storageClient.DeleteObjectAsync(_bucketName, folderToDelete.FullName, null, cancellationToken); } catch { } } } else { throw new NotSupportedException(); } }
/// <inheritdoc /> public Task UnlinkAsync(IUnixFileSystemEntry entry, CancellationToken cancellationToken) { var entryInfo = ((UnixFileSystemEntry)entry).GenericInfo; entryInfo.Delete(); return(Task.CompletedTask); }
/// <inheritdoc/> public async Task <IUnixFileSystemEntry> MoveAsync( IUnixDirectoryEntry parent, IUnixFileSystemEntry source, IUnixDirectoryEntry target, string fileName, CancellationToken cancellationToken) { var parentEntry = (GoogleDriveDirectoryEntry)parent; var targetEntry = (GoogleDriveDirectoryEntry)target; var targetName = FileSystemExtensions.CombinePath(targetEntry.FullName, fileName); if (source is GoogleDriveFileEntry sourceFileEntry) { var newFile = await MoveItem( parentEntry.File.Id, targetEntry.File.Id, sourceFileEntry.File.Id, fileName, cancellationToken); return(new GoogleDriveFileEntry(this, newFile, targetName)); } else { var sourceDirEntry = (GoogleDriveDirectoryEntry)source; var newDir = await MoveItem( parentEntry.File.Id, targetEntry.File.Id, sourceDirEntry.File.Id, fileName, cancellationToken); return(new GoogleDriveDirectoryEntry(this, newDir, targetName)); } }
/// <inheritdoc/> public override async Task <FtpResponse> Process(FtpCommand command, CancellationToken cancellationToken) { var path = command.Argument; var currentPath = Data.Path.Clone(); var fileInfo = await Data.FileSystem.SearchFileAsync(currentPath, path, cancellationToken).ConfigureAwait(false); IUnixFileSystemEntry foundEntry = fileInfo?.Entry; if (foundEntry == null) { var parts = path.Split(new[] { ' ' }, 2); if (parts.Length != 2) { return(new FtpResponse(550, "File not found.")); } if (!parts[0].TryParseTimestamp("UTC", out var modificationTime)) { return(new FtpResponse(550, "File not found.")); } path = parts[1]; currentPath = Data.Path.Clone(); fileInfo = await Data.FileSystem.SearchFileAsync(currentPath, path, cancellationToken).ConfigureAwait(false); if (fileInfo?.Entry == null) { return(new FtpResponse(550, "File not found.")); } foundEntry = await Data.FileSystem.SetMacTimeAsync(fileInfo.Entry, modificationTime, null, null, cancellationToken).ConfigureAwait(false); } return(new FtpResponse(213, $"{foundEntry.LastWriteTime?.ToUniversalTime():yyyyMMddHHmmss.fff}")); }
/// <inheritdoc/> public async Task <IUnixFileSystemEntry> SetMacTimeAsync(IUnixFileSystemEntry entry, DateTimeOffset?modify, DateTimeOffset?access, DateTimeOffset?create, CancellationToken cancellationToken) { var dirEntry = entry as GoogleDriveDirectoryEntry; var fileEntry = entry as GoogleDriveFileEntry; var item = dirEntry == null ? fileEntry?.File : dirEntry.File; if (item == null) { throw new InvalidOperationException(); } var newItemValues = new File() { ModifiedDate = modify?.UtcDateTime, CreatedDate = create?.UtcDateTime, LastViewedByMeDate = access?.UtcDateTime, }; var newItem = await Service.UpdateAsync(item.Id, newItemValues, cancellationToken); var fullName = dirEntry == null ? fileEntry.FullName : dirEntry.FullName; var targetFullName = FileSystemExtensions.CombinePath(fullName.GetParentPath(), newItem.Title); if (dirEntry != null) { return(new GoogleDriveDirectoryEntry(this, newItem, targetFullName, dirEntry.IsRoot)); } return(new GoogleDriveFileEntry(this, newItem, fullName, fileEntry.Size)); }
/// <inheritdoc /> public Task <IUnixFileSystemEntry> MoveAsync( IUnixDirectoryEntry parent, IUnixFileSystemEntry source, IUnixDirectoryEntry target, string fileName, CancellationToken cancellationToken) { var parentEntry = (InMemoryDirectoryEntry)parent; var sourceEntry = (InMemoryFileSystemEntry)source; var targetEntry = (InMemoryDirectoryEntry)target; targetEntry.Children.Add(fileName, source); if (!parentEntry.Children.Remove(source.Name)) { targetEntry.Children.Remove(fileName); throw new FileUnavailableException($"The source file {source.Name} couldn't be found in directory {parentEntry.Name}"); } var now = DateTimeOffset.Now; parentEntry.SetLastWriteTime(now); targetEntry.SetLastWriteTime(now); sourceEntry.Parent = targetEntry; return(Task.FromResult(source)); }
/// <summary> /// Sets the modify/access/create timestamp of a file system item. /// </summary> /// <param name="entry">The <see cref="IUnixFileSystemEntry"/> to change the timestamp for.</param> /// <param name="modify">The modification timestamp.</param> /// <param name="access">The access timestamp.</param> /// <param name="create">The creation timestamp.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>The modified <see cref="IUnixFileSystemEntry"/>.</returns> public Task <IUnixFileSystemEntry> SetMacTimeAsync(IUnixFileSystemEntry entry, DateTimeOffset?modify, DateTimeOffset?access, DateTimeOffset?create, CancellationToken cancellationToken) { var item = ((CustomServerDemoEntry)entry).Info; if (access != null) { item.LastAccessTimeUtc = access.Value.UtcDateTime; } if (modify != null) { item.LastWriteTimeUtc = modify.Value.UtcDateTime; } if (create != null) { item.CreationTimeUtc = create.Value.UtcDateTime; } if (entry is CustomDirectoryEntry dirEntry) { return(Task.FromResult <IUnixFileSystemEntry>(new CustomDirectoryEntry((DirectoryInfo)item, dirEntry.IsRoot, SupportsNonEmptyDirectoryDelete))); } return(Task.FromResult <IUnixFileSystemEntry>(new CustomFileEntry((FileInfo)item))); }
/// <summary> /// Sets the modify/access/create timestamp of a file system item. /// </summary> /// <param name="entry">The <see cref="IUnixFileSystemEntry"/> to change the timestamp for.</param> /// <param name="modify">The modification timestamp.</param> /// <param name="access">The access timestamp.</param> /// <param name="create">The creation timestamp.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>The modified <see cref="IUnixFileSystemEntry"/>.</returns> public Task <IUnixFileSystemEntry> SetMacTimeAsync(IUnixFileSystemEntry entry, DateTimeOffset?modify, DateTimeOffset?access, DateTimeOffset?create, CancellationToken cancellationToken) { var item = ((ServerManagerFileSystemEntry)entry).Info; if (item == null) { throw new InvalidOperationException(); } if (access != null) { item.LastAccessTimeUtc = access.Value.UtcDateTime; } if (modify != null) { item.LastWriteTimeUtc = modify.Value.UtcDateTime; } if (create != null) { item.CreationTimeUtc = create.Value.UtcDateTime; } if (entry is ServerManagerDirectoryEntry dirEntry) { return(Task.FromResult <IUnixFileSystemEntry>(new ServerManagerDirectoryEntry((DirectoryInfo)item, SupportsNonEmptyDirectoryDelete))); } return(Task.FromResult <IUnixFileSystemEntry>(new DotNetFileEntry((FileInfo)item))); }
/// <inheritdoc /> public Task <IUnixFileSystemEntry> MoveAsync( IUnixDirectoryEntry parent, IUnixFileSystemEntry source, IUnixDirectoryEntry target, string fileName, CancellationToken cancellationToken) { var parentEntry = (InMemoryDirectoryEntry)parent; var sourceEntry = (InMemoryFileSystemEntry)source; var targetEntry = (InMemoryDirectoryEntry)target; targetEntry.Children.Add(fileName, source); if (!parentEntry.Children.Remove(source.Name)) { targetEntry.Children.Remove(fileName); return(Task.FromResult <IUnixFileSystemEntry>(null)); } var now = DateTimeOffset.Now; parentEntry.SetLastWriteTime(now); targetEntry.SetLastWriteTime(now); sourceEntry.Parent = targetEntry; return(Task.FromResult(source)); }
/// <inheritdoc/> public string Format(IUnixFileSystemEntry entry) { var currentDirEntry = _pathEntries.Count == 0 ? _fileSystem.Root : _pathEntries.Peek(); var dirEntry = entry as IUnixDirectoryEntry; if (dirEntry != null) return BuildLine(BuildFacts(currentDirEntry, dirEntry, new TypeFact(dirEntry)), entry.Name); return BuildLine(BuildFacts(currentDirEntry, (IUnixFileEntry)entry), entry.Name); }
/// <inheritdoc /> public Task UnlinkAsync(IUnixFileSystemEntry entry, CancellationToken cancellationToken) { var fsEntry = (InMemoryFileSystemEntry)entry; if (fsEntry.Parent?.Children.Remove(entry.Name) ?? false) { fsEntry.Parent.SetLastWriteTime(DateTimeOffset.Now); fsEntry.Parent = null; } return(Task.CompletedTask); }
/// <inheritdoc/> public Task UnlinkAsync(IUnixFileSystemEntry entry, CancellationToken cancellationToken) { if (entry is DotNetDirectoryEntry dirEntry) { dirEntry.Info.Delete(SupportsNonEmptyDirectoryDelete); } else { var fileEntry = (DotNetFileEntry)entry; fileEntry.Info.Delete(); } return(Task.FromResult(0)); }
/// <inheritdoc/> public async Task UnlinkAsync(IUnixFileSystemEntry entry, CancellationToken cancellationToken) { var dirEntry = entry as GoogleDriveDirectoryEntry; if (dirEntry != null) { await Service.TrashAsync(dirEntry.File, cancellationToken); } else { var fileEntry = (GoogleDriveFileEntry)entry; await Service.TrashAsync(fileEntry.File, cancellationToken); } }
public MlstFtpResponse( ISet <string> activeMlstFacts, ClaimsPrincipal user, IUnixFileSystem fileSystem, IUnixFileSystemEntry targetEntry, Stack <IUnixDirectoryEntry> path) : base(250, $" {targetEntry.Name}", "End") { _activeMlstFacts = activeMlstFacts; _user = user; _fileSystem = fileSystem; _targetEntry = targetEntry; _path = path; }
public async Task <IUnixFileSystemEntry> GetEntryByNameAsync(IUnixDirectoryEntry directoryEntry, string name, CancellationToken cancellationToken) { IUnixFileSystemEntry result = null; var parentEntry = (GcsDirectoryEntry)directoryEntry; var fullName = string.Join("/", new string[] { parentEntry.FullName.Trim('/'), name }).Trim('/'); Google.Apis.Storage.v1.Data.Object obj = null; try { obj = await _storageClient.GetObjectAsync(_bucketName, fullName, null, cancellationToken); } catch { } if (obj == null) { var childEntry = new GcsDirectoryEntry(this) { Name = $"{fullName}/" }; var directoryExists = await DirectoryExistsAsync(childEntry); if (directoryExists) { result = childEntry; } } else { if (obj.ContentType != "application/x-directory") { DateTimeOffset?createdTime = null; if (obj.TimeCreated is DateTime created) { createdTime = new DateTimeOffset(created); } DateTimeOffset?updatedTime = null; if (obj.Updated is DateTime updated) { updatedTime = new DateTimeOffset(updated); } return(new GcsFileEntry(this) { Name = obj.Name, Size = Convert.ToInt64(obj.Size), CreatedTime = createdTime, LastWriteTime = updatedTime }); } } return(result); }
/// <inheritdoc/> public Task UnlinkAsync(IUnixFileSystemEntry entry, CancellationToken cancellationToken) { var dirEntry = entry as RemoteDirectoryEntry; if (dirEntry != null) { dirEntry.Info.Delete(SupportsNonEmptyDirectoryDelete); } else { var fileEntry = (RemoteFileEntry)entry; fileEntry.Info.Delete(); } return(Task.FromResult(0)); }
private static string BuildLine(IUnixFileSystemEntry entry, IUnixFileEntry fileEntry, string name) { return string.Format( CultureInfo.InvariantCulture, "{0}{1}{2}{3} {4} {5} {6} {7:D13} {8:MMM dd HH:mm} {9}", fileEntry == null ? "d" : "-", BuildAccessMode(entry.Permissions.User), BuildAccessMode(entry.Permissions.Group), BuildAccessMode(entry.Permissions.Other), entry.NumberOfLinks, entry.Owner, entry.Group, fileEntry?.Size ?? 0, entry.LastWriteTime, name); }
private static string BuildLine(IUnixFileSystemEntry entry, IUnixFileEntry fileEntry, string name) { return(string.Format( CultureInfo.InvariantCulture, "{0}{1}{2}{3} {4} {5} {6} {7:D13} {8:MMM dd HH:mm} {9}", fileEntry == null ? "d" : "-", BuildAccessMode(entry.Permissions.User), BuildAccessMode(entry.Permissions.Group), BuildAccessMode(entry.Permissions.Other), entry.NumberOfLinks, entry.Owner, entry.Group, fileEntry?.Size ?? 0, entry.LastWriteTime, name)); }
/// <inheritdoc/> public Task <IUnixFileSystemEntry> MoveAsync(IUnixDirectoryEntry parent, IUnixFileSystemEntry source, IUnixDirectoryEntry target, string fileName, CancellationToken cancellationToken) { var targetEntry = (DotNetDirectoryEntry)target; var targetName = Path.Combine(targetEntry.Info.FullName, fileName); if (source is DotNetFileEntry sourceFileEntry) { sourceFileEntry.Info.MoveTo(targetName); return(Task.FromResult <IUnixFileSystemEntry>(new DotNetFileEntry(this, new FileInfo(targetName)))); } var sourceDirEntry = (DotNetDirectoryEntry)source; sourceDirEntry.Info.MoveTo(targetName); return(Task.FromResult <IUnixFileSystemEntry>(new DotNetDirectoryEntry(this, new DirectoryInfo(targetName), false))); }
/// <inheritdoc/> public Task <IUnixFileSystemEntry> MoveAsync(IUnixDirectoryEntry parent, IUnixFileSystemEntry source, IUnixDirectoryEntry target, string fileName, CancellationToken cancellationToken) { var targetEntry = (CustomDirectoryEntry)target; var targetName = Path.Combine(targetEntry.Info.FullName, fileName); if (source is CustomFileEntry sourceFileEntry) { sourceFileEntry.FileInfo.MoveTo(targetName); return(Task.FromResult <IUnixFileSystemEntry>(new CustomFileEntry(new FileInfo(targetName)))); } var sourceDirEntry = (CustomDirectoryEntry)source; sourceDirEntry.DirectoryInfo.MoveTo(targetName); return(Task.FromResult <IUnixFileSystemEntry>(new CustomDirectoryEntry(new DirectoryInfo(targetName), false, SupportsNonEmptyDirectoryDelete))); }
/// <inheritdoc/> public string Format(IUnixFileSystemEntry entry, string name) { switch (name) { case ".": return FormatThisDirectoryEntry(); case "..": return FormatParentDirectoryEntry(); } var currentDirEntry = _enumerator.CurrentDirectory; var dirEntry = entry as IUnixDirectoryEntry; if (dirEntry != null) return BuildLine(BuildFacts(currentDirEntry, dirEntry, new TypeFact(dirEntry)), dirEntry.IsRoot ? string.Empty : name ?? entry.Name); return BuildLine(BuildFacts(currentDirEntry, (IUnixFileEntry)entry), name ?? entry.Name); }
public Task UnlinkAsync(IUnixFileSystemEntry entry, CancellationToken cancellationToken) { if (((AzureBlobFileSystemEntry)entry).IsFolder) { var dir = (CloudBlobDirectory)((AzureBlobDirectoryEntry)entry).Item; foreach (IListBlobItem item in dir.ListBlobs(true)) { ((CloudBlockBlob)item).Delete(); } } else { var file = (CloudBlockBlob)((AzureBlobFileEntry)entry).Item; file.Delete(); } return(Task.FromResult(0)); }
/// <inheritdoc/> public async Task UnlinkAsync(IUnixFileSystemEntry entry, CancellationToken cancellationToken) { var body = new File { Trashed = true, }; if (entry is GoogleDriveDirectoryEntry dirEntry) { await Service.Files.Update(body, dirEntry.File.Id).ExecuteAsync(cancellationToken); } else { var fileEntry = (GoogleDriveFileEntry)entry; await Service.Files.Update(body, fileEntry.File.Id).ExecuteAsync(cancellationToken); } }
/// <inheritdoc/> public Task UnlinkAsync(IUnixFileSystemEntry entry, CancellationToken cancellationToken) { if (entry is ServerManagerDirectoryEntry dirEntry) { if (dirEntry.Info == null) { throw new InvalidOperationException(); } ((DirectoryInfo)dirEntry.Info).Delete(SupportsNonEmptyDirectoryDelete); } else { var fileEntry = (ServerManagerFileEntry)entry; fileEntry.Info.Delete(); } return(Task.FromResult(0)); }
/// <inheritdoc /> public Task UnlinkAsync(IUnixFileSystemEntry entry, CancellationToken cancellationToken) { var fsEntry = (InMemoryFileSystemEntry)entry; var parent = fsEntry.Parent; if (parent != null) { lock (parent.ChildrenLock) { if (parent.Children.Remove(entry.Name)) { parent.SetLastWriteTime(DateTimeOffset.Now); fsEntry.Parent = null; } } } return(Task.CompletedTask); }
/// <summary> /// Sets the modify/access/create timestamp of a file system item. /// </summary> /// <param name="entry">The <see cref="IUnixFileSystemEntry"/> to change the timestamp for.</param> /// <param name="modify">The modification timestamp.</param> /// <param name="access">The access timestamp.</param> /// <param name="create">The creation timestamp.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>The modified <see cref="IUnixFileSystemEntry"/>.</returns> public Task <IUnixFileSystemEntry> SetMacTimeAsync(IUnixFileSystemEntry entry, DateTimeOffset?modify, DateTimeOffset?access, DateTimeOffset?create, CancellationToken cancellationToken) { var dirEntry = entry as DotNetDirectoryEntry; var fileEntry = entry as DotNetFileEntry; FileSystemInfo item; if (dirEntry != null) { item = dirEntry.Info; } else if (fileEntry != null) { item = fileEntry.Info; } else { throw new ArgumentException("Argument must be of type DotNetDirectoryEntry or DotNetFileEntry", nameof(entry)); } if (access != null) { item.LastAccessTimeUtc = access.Value.UtcDateTime; } if (modify != null) { item.LastWriteTimeUtc = modify.Value.UtcDateTime; } if (create != null) { item.CreationTimeUtc = create.Value.UtcDateTime; } if (dirEntry != null) { return(Task.FromResult <IUnixFileSystemEntry>(new DotNetDirectoryEntry(this, (DirectoryInfo)item, dirEntry.IsRoot))); } return(Task.FromResult <IUnixFileSystemEntry>(new DotNetFileEntry(this, (FileInfo)item))); }
/// <inheritdoc/> public string Format(IUnixFileSystemEntry entry, string name) { switch (name) { case ".": return(FormatThisDirectoryEntry()); case "..": return(FormatParentDirectoryEntry()); } var currentDirEntry = _enumerator.CurrentDirectory; if (entry is IUnixDirectoryEntry dirEntry) { return(BuildLine(BuildFacts(currentDirEntry, dirEntry, new TypeFact(dirEntry)), dirEntry.IsRoot ? string.Empty : name ?? entry.Name)); } return(BuildLine(BuildFacts(currentDirEntry, (IUnixFileEntry)entry), name ?? entry.Name)); }
/// <inheritdoc /> public Task <IUnixFileSystemEntry> SetMacTimeAsync( IUnixFileSystemEntry entry, DateTimeOffset?modify, DateTimeOffset?access, DateTimeOffset?create, CancellationToken cancellationToken) { var fsEntry = (InMemoryFileSystemEntry)entry; if (modify != null) { fsEntry.SetLastWriteTime(modify.Value); } if (create != null) { fsEntry.SetCreateTime(create.Value); } return(Task.FromResult(entry)); }
private static string BuildLine(IUnixFileSystemEntry entry, IUnixFileEntry fileEntry, string name) { var lastWriteDate = entry.LastWriteTime ?? new DateTimeOffset(new DateTime(1970, 01, 01)); var format = lastWriteDate.Year == DateTimeOffset.UtcNow.Year ? "{0}{1}{2}{3} {4} {5} {6} {7} {8:MMM dd HH:mm} {9}" : "{0}{1}{2}{3} {4} {5} {6} {7} {8:MMM dd yyyy} {9}"; return(string.Format( CultureInfo.InvariantCulture, format, fileEntry == null ? "d" : "-", BuildAccessMode(entry.Permissions.User), BuildAccessMode(entry.Permissions.Group), BuildAccessMode(entry.Permissions.Other), entry.NumberOfLinks, entry.Owner, entry.Group, fileEntry?.Size ?? 0, lastWriteDate, name)); }
/// <inheritdoc /> public Task <IUnixFileSystemEntry> MoveAsync( IUnixDirectoryEntry parent, IUnixFileSystemEntry source, IUnixDirectoryEntry target, string fileName, CancellationToken cancellationToken) { var sourceInfo = ((UnixFileSystemEntry)source).GenericInfo; var targetEntry = (UnixDirectoryEntry)target; var targetInfo = targetEntry.Info; var sourceEntryName = sourceInfo.FullName; var targetEntryName = UnixPath.Combine(targetInfo.FullName, fileName); if (Stdlib.rename(sourceEntryName, targetEntryName) == -1) { throw new InvalidOperationException("The entry couldn't be moved."); } var targetEntryInfo = UnixFileSystemInfo.GetFileSystemEntry(targetEntryName); return(Task.FromResult(CreateEntry(targetEntry, targetEntryInfo))); }
/// <inheritdoc /> public Task <IUnixFileSystemEntry> SetMacTimeAsync( IUnixFileSystemEntry entry, DateTimeOffset?modify, DateTimeOffset?access, DateTimeOffset?create, CancellationToken cancellationToken) { if (access == null && modify == null) { return(Task.FromResult(entry)); } var entryInfo = ((UnixFileSystemEntry)entry).GenericInfo; var times = new Timeval[2]; if (access != null) { times[0] = ToTimeval(access.Value.UtcDateTime); } else { times[0] = ToTimeval(entryInfo.LastAccessTimeUtc); } if (modify != null) { times[1] = ToTimeval(modify.Value.UtcDateTime); } else { times[1] = ToTimeval(entryInfo.LastWriteTimeUtc); } Syscall.utimes(entryInfo.FullName, times); entryInfo.Refresh(); return(Task.FromResult(entry)); }
/// <inheritdoc/> public async Task <IUnixFileSystemEntry> SetMacTimeAsync( IUnixFileSystemEntry entry, DateTimeOffset?modify, DateTimeOffset?access, DateTimeOffset?create, CancellationToken cancellationToken) { var dirEntry = entry as GoogleDriveDirectoryEntry; var fileEntry = entry as GoogleDriveFileEntry; var item = dirEntry == null ? fileEntry?.File : dirEntry.File; if (item == null) { throw new InvalidOperationException(); } var newItemValues = new File() { ModifiedTime = modify?.UtcDateTime, CreatedTime = create?.UtcDateTime, ViewedByMeTime = access?.UtcDateTime, }; var request = Service.Files.Update(newItemValues, item.Id); request.Fields = FileExtensions.DefaultFileFields; var newItem = await request.ExecuteAsync(cancellationToken).ConfigureAwait(false); var fullName = dirEntry == null ? fileEntry.FullName : dirEntry.FullName; var targetFullName = FileSystemExtensions.CombinePath(fullName.GetParentPath(), newItem.Name); if (dirEntry != null) { return(new GoogleDriveDirectoryEntry(newItem, targetFullName, dirEntry.IsRoot)); } return(new GoogleDriveFileEntry(newItem, fullName, fileEntry.Size)); }
/// <inheritdoc/> public Task <IUnixFileSystemEntry> MoveAsync(IUnixDirectoryEntry parent, IUnixFileSystemEntry source, IUnixDirectoryEntry target, string fileName, CancellationToken cancellationToken) { var targetEntry = (ServerManagerDirectoryEntry)target; if (targetEntry.Info == null) { throw new InvalidOperationException(); } var targetName = Path.Combine(targetEntry.Info.FullName, fileName); if (source is ServerManagerFileEntry sourceFileEntry) { ((FileInfo)sourceFileEntry.Info).MoveTo(targetName); return(Task.FromResult <IUnixFileSystemEntry>(new ServerManagerFileEntry(targetEntry.Server, new FileInfo(targetName)))); } var sourceDirEntry = (ServerManagerDirectoryEntry)source; ((DirectoryInfo)sourceDirEntry.Info).MoveTo(targetName); return(Task.FromResult <IUnixFileSystemEntry>(new ServerManagerDirectoryEntry(targetEntry.Server, new DirectoryInfo(targetName), SupportsNonEmptyDirectoryDelete, targetEntry.IsRoot))); }
/// <inheritdoc/> public async Task<IUnixFileSystemEntry> MoveAsync(IUnixDirectoryEntry parent, IUnixFileSystemEntry source, IUnixDirectoryEntry target, string fileName, CancellationToken cancellationToken) { var parentEntry = (GoogleDriveDirectoryEntry)parent; var targetEntry = (GoogleDriveDirectoryEntry)target; var targetName = FileSystemExtensions.CombinePath(targetEntry.FullName, fileName); var sourceFileEntry = source as GoogleDriveFileEntry; if (sourceFileEntry != null) { var newFile = await Service.MoveAsync(sourceFileEntry.File, parentEntry.File.Id, targetEntry.File, fileName, cancellationToken); return new GoogleDriveFileEntry(this, newFile, targetName); } var sourceDirEntry = (GoogleDriveDirectoryEntry)source; var newDir = await Service.MoveAsync(sourceDirEntry.File, parentEntry.File.Id, targetEntry.File, fileName, cancellationToken); return new GoogleDriveDirectoryEntry(this, newDir, targetName); }
/// <inheritdoc/> public string Format(IUnixFileSystemEntry entry) { var fileEntry = entry as IUnixFileEntry; return BuildLine(entry, fileEntry, entry.Name); }
/// <summary> /// Sets the modify/access/create timestamp of a file system item /// </summary> /// <param name="entry">The <see cref="IUnixFileSystemEntry"/> to change the timestamp for</param> /// <param name="modify">The modification timestamp</param> /// <param name="access">The access timestamp</param> /// <param name="create">The creation timestamp</param> /// <param name="cancellationToken">The cancellation token</param> /// <returns>The modified <see cref="IUnixFileSystemEntry"/></returns> public Task<IUnixFileSystemEntry> SetMacTimeAsync(IUnixFileSystemEntry entry, DateTimeOffset? modify, DateTimeOffset? access, DateTimeOffset? create, CancellationToken cancellationToken) { var dirEntry = entry as DotNetDirectoryEntry; var fileEntry = entry as DotNetFileEntry; var item = dirEntry == null ? (FileSystemInfo)fileEntry.Info : dirEntry.Info; if (access != null) item.LastAccessTimeUtc = access.Value.UtcDateTime; if (modify != null) item.LastWriteTimeUtc = modify.Value.UtcDateTime; if (create != null) item.CreationTimeUtc = create.Value.UtcDateTime; if (dirEntry != null) return Task.FromResult<IUnixFileSystemEntry>(new DotNetDirectoryEntry(this, (DirectoryInfo)item, dirEntry.IsRoot)); return Task.FromResult<IUnixFileSystemEntry>(new DotNetFileEntry(this, (FileInfo)item)); }
/// <inheritdoc/> public string Format(IUnixFileSystemEntry entry, string name) { return name ?? entry.Name; }
/// <inheritdoc/> public string Format(IUnixFileSystemEntry entry) { return entry.Name; }
/// <inheritdoc/> public Task<IUnixFileSystemEntry> MoveAsync(IUnixDirectoryEntry parent, IUnixFileSystemEntry source, IUnixDirectoryEntry target, string fileName, CancellationToken cancellationToken) { throw new NotSupportedException(); }
/// <inheritdoc/> public Task<IUnixFileSystemEntry> SetMacTimeAsync(IUnixFileSystemEntry entry, DateTimeOffset? modify, DateTimeOffset? access, DateTimeOffset? create, CancellationToken cancellationToken) { throw new NotSupportedException(); }
/// <summary> /// Initializes a new instance of the <see cref="TypeFact"/> class. /// </summary> /// <param name="entry">The file system entry to get the <code>type</code> fact for</param> public TypeFact(IUnixFileSystemEntry entry) : this(entry is IUnixFileEntry ? "file" : "dir") { }
/// <inheritdoc/> public Task UnlinkAsync(IUnixFileSystemEntry entry, CancellationToken cancellationToken) { throw new NotSupportedException(); }
/// <inheritdoc/> public async Task<IUnixFileSystemEntry> SetMacTimeAsync(IUnixFileSystemEntry entry, DateTimeOffset? modify, DateTimeOffset? access, DateTimeOffset? create, CancellationToken cancellationToken) { var dirEntry = entry as GoogleDriveDirectoryEntry; var fileEntry = entry as GoogleDriveFileEntry; var item = dirEntry == null ? fileEntry?.File : dirEntry.File; if (item == null) throw new InvalidOperationException(); var newItemValues = new File() { ModifiedDate = modify?.UtcDateTime, CreatedDate = create?.UtcDateTime, LastViewedByMeDate = access?.UtcDateTime, }; var newItem = await Service.UpdateAsync(item.Id, newItemValues, cancellationToken); var fullName = dirEntry == null ? fileEntry.FullName : dirEntry.FullName; var targetFullName = FileSystemExtensions.CombinePath(fullName.GetParentPath(), newItem.Title); if (dirEntry != null) return new GoogleDriveDirectoryEntry(this, newItem, targetFullName, dirEntry.IsRoot); return new GoogleDriveFileEntry(this, newItem, fullName, fileEntry.Size); }
/// <inheritdoc/> public async Task<IUnixFileSystemEntry> MoveAsync(IUnixDirectoryEntry parent, IUnixFileSystemEntry source, IUnixDirectoryEntry target, string fileName, CancellationToken cancellationToken) { var sourceItem = ((OneDriveFileSystemEntry)source).Item; var sourceId = sourceItem.Id; var newParentItem = ((OneDriveDirectoryEntry)target).Item; var newParentRef = new ItemReference() { Id = newParentItem.Id, }; _cache.Remove(GetFileId(sourceItem)); var newItem = await Service.MoveAsync(Drive.Id, sourceId, fileName, newParentRef, cancellationToken); _cache.Set(GetFileId(newItem), newItem, _defaultCacheTimeSpan); return await ConvertToUnixFileSystemEntry(newItem, cancellationToken); }
/// <inheritdoc/> public async Task UnlinkAsync(IUnixFileSystemEntry entry, CancellationToken cancellationToken) { var entryItem = ((OneDriveFileSystemEntry)entry).Item; await Service.DeleteAsync(Drive.Id, entryItem.Id, cancellationToken); }
/// <inheritdoc/> public async Task<IUnixFileSystemEntry> SetMacTimeAsync(IUnixFileSystemEntry entry, DateTimeOffset? modify, DateTimeOffset? access, DateTimeOffset? create, CancellationToken cancellationToken) { var item = ((OneDriveFileSystemEntry)entry).Item; await _uploadsLock.WaitAsync(cancellationToken); try { var id = GetFileId(item); BackgroundUpload uploader; if (_uploads.TryGetValue(id, out uploader)) { if (uploader.ItemChanges == null) uploader.ItemChanges = new Item(); if (uploader.ItemChanges.FileSystemInfo == null) uploader.ItemChanges.FileSystemInfo = new FileSystemInfo(); if (item.FileSystemInfo == null) item.FileSystemInfo = new FileSystemInfo(); if (uploader.Item.FileSystemInfo == null) uploader.Item.FileSystemInfo = new FileSystemInfo(); if (modify != null) { uploader.ItemChanges.FileSystemInfo.LastModifiedDateTime = modify; uploader.Item.FileSystemInfo.LastModifiedDateTime = modify; item.FileSystemInfo.LastModifiedDateTime = modify; } if (create != null) { uploader.ItemChanges.FileSystemInfo.CreatedDateTime = create; uploader.Item.FileSystemInfo.CreatedDateTime = create; item.FileSystemInfo.CreatedDateTime = create; } return entry; } } finally { _uploadsLock.Release(); } var updateItem = new Item() { FileSystemInfo = new FileSystemInfo() }; if (modify != null) updateItem.FileSystemInfo.LastModifiedDateTime = modify; if (create != null) updateItem.FileSystemInfo.CreatedDateTime = create; var newItem = await Service.UpdateAsync(Drive.Id, item.Id, updateItem, cancellationToken); _cache.Set(GetFileId(newItem), newItem, _defaultCacheTimeSpan); if (newItem.Folder != null) return new OneDriveDirectoryEntry(this, newItem, false); return new OneDriveFileEntry(this, newItem, null); }
/// <inheritdoc/> public Task UnlinkAsync(IUnixFileSystemEntry entry, CancellationToken cancellationToken) { var dirEntry = entry as DotNetDirectoryEntry; if (dirEntry != null) { dirEntry.Info.Delete(SupportsNonEmptyDirectoryDelete); } else { var fileEntry = (DotNetFileEntry)entry; fileEntry.Info.Delete(); } return Task.FromResult(0); }
/// <inheritdoc/> public Task<IUnixFileSystemEntry> MoveAsync(IUnixDirectoryEntry parent, IUnixFileSystemEntry source, IUnixDirectoryEntry target, string fileName, CancellationToken cancellationToken) { var targetEntry = (DotNetDirectoryEntry)target; var targetName = Path.Combine(targetEntry.Info.FullName, fileName); var sourceFileEntry = source as DotNetFileEntry; if (sourceFileEntry != null) { sourceFileEntry.Info.MoveTo(targetName); return Task.FromResult<IUnixFileSystemEntry>(new DotNetFileEntry(this, new FileInfo(targetName))); } var sourceDirEntry = (DotNetDirectoryEntry)source; sourceDirEntry.Info.MoveTo(targetName); return Task.FromResult<IUnixFileSystemEntry>(new DotNetDirectoryEntry(this, new DirectoryInfo(targetName), false)); }
/// <summary> /// Sets the modify/access/create timestamp of a file system item /// </summary> /// <param name="entry">The <see cref="IUnixFileSystemEntry"/> to change the timestamp for</param> /// <param name="modify">The modification timestamp</param> /// <param name="access">The access timestamp</param> /// <param name="create">The creation timestamp</param> /// <param name="cancellationToken">The cancellation token</param> /// <returns>The modified <see cref="IUnixFileSystemEntry"/></returns> public Task<IUnixFileSystemEntry> SetMacTimeAsync(IUnixFileSystemEntry entry, DateTimeOffset? modify, DateTimeOffset? access, DateTimeOffset? create, CancellationToken cancellationToken) { var dirEntry = entry as DotNetDirectoryEntry; var fileEntry = entry as DotNetFileEntry; FileSystemInfo item; if (dirEntry != null) { item = dirEntry.Info; } else if (fileEntry != null) { item = fileEntry.Info; } else { throw new ArgumentException("Argument must be of type DotNetDirectoryEntry or DotNetFileEntry", nameof(entry)); } if (access != null) item.LastAccessTimeUtc = access.Value.UtcDateTime; if (modify != null) item.LastWriteTimeUtc = modify.Value.UtcDateTime; if (create != null) item.CreationTimeUtc = create.Value.UtcDateTime; if (dirEntry != null) return Task.FromResult<IUnixFileSystemEntry>(new DotNetDirectoryEntry(this, (DirectoryInfo)item, dirEntry.IsRoot)); return Task.FromResult<IUnixFileSystemEntry>(new DotNetFileEntry(this, (FileInfo)item)); }