/// <summary> /// Async version of DeepCopyTo(...) /// </summary> public Task DeepCopyToAsync(FileSystemDirectory target, DirCopyFlags flags = DirCopyFlags.All, int bufferSize = 64 * 1024, Func <FileSystemSessionItem, bool> filter = null, Func <FileSystemSessionItem, bool> cancel = null) { return(m_FileSystem.DoDirectoryDeepCopyAsync(this, target, flags, bufferSize, filter, cancel)); }
/// <summary> /// Implements asynchronous deep copy of folders where destination folder may belong to a different file system. /// The specifics of implementation may be dictated by particular file systems, i.e.: asynchronous strategies for getting file /// lists may depend on the particular system. /// </summary> protected internal virtual Task DoDirectoryDeepCopyAsync(FileSystemDirectory dirFrom, FileSystemDirectory dirTo, FileSystemDirectory.DirCopyFlags flags = FileSystemDirectory.DirCopyFlags.All, int bufferSize = 64 * 1024, Func <FileSystemSessionItem, bool> filter = null, Func <FileSystemSessionItem, bool> cancel = null) { return(TaskUtils.AsCompletedTask(() => dirFrom.DeepCopyTo(dirTo, flags, bufferSize, filter, cancel))); }
private void doLevel(FileSystemDirectory level, stats st) { try { deleteLocalFiles(level, st); } catch (Exception localError) { log(MessageType.Error, "deleteLevel", "Deleting local files in '{0}'. Error: {1}".Args(level.Path, localError.ToMessageWithType(), localError)); } if (Recurse) { var sdNames = level.SubDirectoryNames; foreach (var sdName in sdNames) { if (!App.Active) { return; } var subdir = level.GetSubDirectory(sdName); if (subdir != null) { st.DirCount++; doLevel(subdir, st); subdir.Dispose(); } if (DeleteEmptyDirs) { subdir = level.GetSubDirectory(sdName); if (subdir != null) { var fcnt = subdir.FileNames.Count(); if (fcnt == 0) { subdir.Delete(); st.DelDirCount++; } subdir.Dispose(); } } } } }
/// <summary> /// Performs a deep copy of this directory into another directory that may belong to a different file system. /// This method allows to copy directory trees between different file systems i.e. from SVN into AmazonS3 or local file system etc. /// </summary> /// <param name="target">Target directory where the files will be placed. It's name does not have to be the same as the source's name</param> /// <param name="flags">Copy flags that specify what to copy</param> /// <param name="bufferSize">Copy buffer size</param> /// <param name="filter">Optional filter function</param> /// <param name="cancel">Optional cancellation function. Return true to abort copying</param> public void DeepCopyTo(FileSystemDirectory target, DirCopyFlags flags = DirCopyFlags.All, int bufferSize = 64 * 1024, Func <FileSystemSessionItem, bool> filter = null, Func <FileSystemSessionItem, bool> cancel = null) { const int MAX_BUFFER = 64 * 1024 * 1024; if (bufferSize <= 0) { bufferSize = 4 * 1024; } if (bufferSize > MAX_BUFFER) { bufferSize = MAX_BUFFER; } var buffer = new byte[bufferSize]; deepCopyTo(target, flags, buffer, filter, cancel); }
private void deleteLocalFiles(FileSystemDirectory level, stats st) { var nameIncludePattern = NameIncludePattern; var nameExcludePattern = NameExcludePattern; var canSize = level.FileSystem.InstanceCapabilities.SupportsFileSizes; var canModDates = level.FileSystem.InstanceCapabilities.SupportsLastAccessTimestamps; var min = MinSize; var max = MaxSize; var lmf = LastModifyFrom; var lmt = LastModifyTo; var lmah = LastModifyAgoHrs; var cutoffAgoDate = lmah.HasValue ? App.TimeSource.UTCNow.AddHours(-lmah.Value) : DateTime.MinValue; var fnames = level.FileNames; foreach (var fname in fnames) { st.FileCount++; if (nameIncludePattern != null && !Azos.Text.Utils.MatchPattern(fname, nameIncludePattern)) { continue; } if (nameExcludePattern != null && Azos.Text.Utils.MatchPattern(fname, nameExcludePattern)) { continue; } var file = level.GetFile(fname); if (file == null) { continue; } if (min.HasValue || max.HasValue) { if (canSize) { var size = file.Size; if (min.HasValue && size < min.Value) { continue; } if (max.HasValue && size > max.Value) { continue; } } else { continue; } } if (lmf.HasValue || lmt.HasValue || lmah.HasValue) { if (canModDates) { var fdt = file.ModificationTimestamp; if (fdt.HasValue) { if (lmf.HasValue && fdt.Value < lmf.Value) { continue; } if (lmt.HasValue && fdt.Value > lmt.Value) { continue; } if (lmah.HasValue && fdt.Value > cutoffAgoDate) { continue; } } } else { continue; } } file.Delete(); st.DelFileCount++; } }
private void deepCopyTo(FileSystemDirectory target, DirCopyFlags flags, byte[] buffer, Func <FileSystemSessionItem, bool> filter, Func <FileSystemSessionItem, bool> cancel = null) { target.CheckCanChange(); if (flags.HasFlag(DirCopyFlags.Directories)) { foreach (var sdn in this.SubDirectoryNames) { using (var sdir = this.GetSubDirectory(sdn)) if (filter == null || filter(sdir)) { if (cancel != null && cancel(sdir)) { return; } using (var newSDir = target.CreateDirectory(sdn)) { copyCommonAttributes(sdir, newSDir, buffer, flags); if (flags.HasFlag(DirCopyFlags.Readonly) && this.FileSystem.InstanceCapabilities.SupportsReadonlyDirectories && target.FileSystem.InstanceCapabilities.SupportsReadonlyDirectories) { newSDir.ReadOnly = sdir.ReadOnly; } sdir.deepCopyTo(newSDir, flags, buffer, filter, cancel); } }//if } } if (flags.HasFlag(DirCopyFlags.Files)) { foreach (var fn in this.FileNames) { using (var file = this.GetFile(fn)) if (filter == null || filter(file)) { if (cancel != null && cancel(file)) { return; } using (var newFile = target.CreateFile(fn)) { copyCommonAttributes(file, newFile, buffer, flags); if (flags.HasFlag(DirCopyFlags.Readonly) && this.FileSystem.InstanceCapabilities.SupportsReadonlyFiles && target.FileSystem.InstanceCapabilities.SupportsReadonlyFiles) { newFile.ReadOnly = file.ReadOnly; } copyStream(file.FileStream, newFile.FileStream, buffer); } } } } }//deepCopyTo
/// <summary> /// Async version of <see cref="DoCreateDirectory(FileSystemDirectory, string)"/>. /// This base/default implementation just synchronously calls <see cref="DoCreateDirectory(FileSystemDirectory, string)"/> and /// returns already completed Task with result returned by <see cref="DoCreateDirectory(FileSystemDirectory, string)"/> /// </summary> protected internal virtual Task <FileSystemDirectory> DoCreateDirectoryAsync(FileSystemDirectory dir, string name) { return(TaskUtils.AsCompletedTask(() => DoCreateDirectory(dir, name))); }
/// <summary> /// Async version of <see cref="DoCreateFile(FileSystemDirectory, string, string, bool)"/>. /// This base/default implementation just synchronously calls <see cref="DoCreateFile(FileSystemDirectory, string, string, bool)"/> and /// returns already completed Task with result returned by <see cref="DoCreateFile(FileSystemDirectory, string, string, bool)"/> /// </summary> protected internal virtual Task <FileSystemFile> DoCreateFileAsync(FileSystemDirectory dir, string name, string localFile, bool readOnly) { return(TaskUtils.AsCompletedTask(() => DoCreateFile(dir, name, localFile, readOnly))); }
/// <summary> /// Override to create a directory. /// This method may be called by multiple threads /// </summary> protected internal abstract FileSystemDirectory DoCreateDirectory(FileSystemDirectory dir, string name);
/// <summary> /// Override to create a file from local file. /// This method may be called by multiple threads /// </summary> protected internal abstract FileSystemFile DoCreateFile(FileSystemDirectory dir, string name, string localFile, bool readOnly);
/// <summary> /// Async version of <see cref="DoCreateFile(FileSystemDirectory, string, int)"/>. /// This base/default implementation just synchronously calls <see cref="DoCreateFile(FileSystemDirectory, string, int)"/> and /// returns already completed Task with result returned by <see cref="DoCreateFile(FileSystemDirectory, string, int)"/> /// </summary> protected internal virtual Task <FileSystemFile> DoCreateFileAsync(FileSystemDirectory dir, string name, int size) { return(TaskUtils.AsCompletedTask(() => DoCreateFile(dir, name, size))); }
/// <summary> /// Override to create a file. /// This method may be called by multiple threads /// </summary> protected internal abstract FileSystemFile DoCreateFile(FileSystemDirectory dir, string name, int size);
/// <summary> /// Async version of <see cref="DoGetFileNames(FileSystemDirectory, bool)"/>. /// This base/default implementation just synchronously calls <see cref="DoGetFileNames(FileSystemDirectory, bool)"/> and /// returns already completed Task with result returned by <see cref="DoGetFileNames(FileSystemDirectory, bool)"/> /// </summary> protected internal virtual Task <IEnumerable <string> > DoGetFileNamesAsync(FileSystemDirectory directory, bool recursive) { return(TaskUtils.AsCompletedTask(() => DoGetFileNames(directory, recursive))); }
/// <summary> /// Override to get file names in directory. If directory is null then root is assumed. /// This method may be called by multiple threads /// </summary> protected internal abstract IEnumerable <string> DoGetFileNames(FileSystemDirectory directory, bool recursive);