Esempio n. 1
0
 /// <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));
 }
Esempio n. 2
0
 /// <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)));
 }
Esempio n. 3
0
        private void deepCopyTo(FileSystemDirectory target, DirCopyFlags flags, byte[] buffer, Func <FileSystemSessionItem, bool> filter)
        {
            target.CheckCanChange();

            if (flags.HasFlag(DirCopyFlags.Directories))
            {
                foreach (var sdn in this.SubDirectoryNames)
                {
                    using (var sdir = this.GetSubDirectory(sdn))
                        if (filter == null || filter(sdir))
                        {
                            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);
                            }
                        }
                }
            }

            if (flags.HasFlag(DirCopyFlags.Files))
            {
                foreach (var fn in this.FileNames)
                {
                    using (var file = this.GetFile(fn))
                        if (filter == null || filter(file))
                        {
                            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
Esempio n. 4
0
 public static void DeleteAllData()
 {
     FileSystemDirectory folder = new FileSystemDirectory(SystemSession, "/", "", null);
     IEnumerable<string> files = folder.FileNames;
     foreach (string file in files)
     {
         FileSystemFile fileo = new FileSystemFile(SystemSession, "/", file, null);
         fileo.Delete();
     }
     IEnumerable<string> folders = folder.SubDirectoryNames;
     foreach (string f in folders)
     {
         FileSystemDirectory fld = new FileSystemDirectory(SystemSession, "/", f, null);
         fld.Delete();
     }
 }
Esempio n. 5
0
        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();
                        }
                    }
                }
            }
        }
Esempio n. 6
0
        /// <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>
        public void DeepCopyTo(FileSystemDirectory target, DirCopyFlags flags = DirCopyFlags.All, int bufferSize = 64 * 1024, Func <FileSystemSessionItem, bool> filter = 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);
        }
Esempio n. 7
0
        public static void InitTestData()
        {
            DeleteAllData();

            FileSystemDirectory folder = new FileSystemDirectory(SystemSession, "/", "", null);
            folder.CreateDirectory("Folder1");
            folder.CreateDirectory("Folder2");
            folder.CreateDirectory("Folder3");
            folder.CreateFile("file1.txt");
            folder.CreateFile("file2.txt");
            folder.CreateFile("file3.txt");

            FileSystemDirectory folder1 = new FileSystemDirectory(SystemSession, "/", "Folder1", null);
            folder1.CreateFile("f1.txt");
            FileSystemDirectory folder2 = new FileSystemDirectory(SystemSession, "/", "Folder2", null);
            folder2.CreateFile("f2.txt");
            FileSystemDirectory folder3 = new FileSystemDirectory(SystemSession, "/", "Folder3", null);
            folder3.CreateFile("f3.txt");
        }
Esempio n. 8
0
 /// <summary>
 /// Override to create a directory.
 /// This method may be called by miltiple threads
 /// </summary>
 protected internal abstract FileSystemDirectory DoCreateDirectory(FileSystemDirectory dir, string name);
Esempio n. 9
0
 /// <summary>
 /// Override to create a file from local file.
 /// This method may be called by miltiple threads
 /// </summary>
 protected internal abstract FileSystemFile DoCreateFile(FileSystemDirectory dir, string name, string localFile, bool readOnly);
Esempio n. 10
0
 /// <summary>
 /// Override to create a file.
 /// This method may be called by miltiple threads
 /// </summary>
 protected internal abstract FileSystemFile DoCreateFile(FileSystemDirectory dir, string name, int size);
Esempio n. 11
0
 /// <summary>
 /// Override to get file names in directory. If directory is null then root is assumed.
 /// This method may be called by miltiple threads
 /// </summary>
 protected internal abstract IEnumerable <string> DoGetFileNames(FileSystemDirectory directory, bool recursive);
Esempio n. 12
0
 protected internal override FileSystemDirectory DoCreateDirectory(FileSystemDirectory dir, string name)
 {
     DropBoxObjectMetadata file = _fileStore.CreateDirectory(dir.Path, name, 5);
     DropBoxObjectHandler handler = new DropBoxObjectHandler(file);
     return new FileSystemDirectory(dir.Session, dir.Path, name, handler);
 }
Esempio n. 13
0
        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();
              }
            }

              }
            }
        }
Esempio n. 14
0
 /// <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); 
 }
Esempio n. 15
0
 private bool folderExists(FileSystemDirectory folder)
 {
   var handle = (S3V4FSH)folder.Handle;
   return S3V4.FolderExists(handle.Path, S3_ACCESSKEY, S3_SECRETKEY, S3_BUCKET, S3_REGION, 0); 
 }
Esempio n. 16
0
        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 && !NFX.Parsing.Utils.MatchPattern(fname, nameIncludePattern))
                {
                    continue;
                }
                if (nameExcludePattern != null && NFX.Parsing.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++;
            }
        }
Esempio n. 17
0
 /// <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)));
 }
Esempio n. 18
0
 /// <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)));
 }
Esempio n. 19
0
 /// <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)));
 }
Esempio n. 20
0
 /// <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)));
 }
Esempio n. 21
0
 protected internal override IEnumerable<string> DoGetFileNames(FileSystemDirectory directory, bool recursive)
 {
     return _metadataStore.GetObjectNames(DropBoxObjectType.File, directory.Path, recursive, 5);
 }
Esempio n. 22
0
 protected internal override FileSystemFile DoCreateFile(FileSystemDirectory dir, string name, int size)
 {
     DropBoxObjectMetadata dropBoxObjectMetadata = _fileStore.CreateFile(CombinePaths(dir.Path, name), 5);
     return new FileSystemFile(dir.Session, DropBoxPathUtils.GetParentPathFromPath(dropBoxObjectMetadata.Path),
                               dropBoxObjectMetadata.Name,
                               new DropBoxObjectHandler(dropBoxObjectMetadata));
 }
Esempio n. 23
0
        /// <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);
        }
Esempio n. 24
0
 protected internal override FileSystemFile DoCreateFile(FileSystemDirectory dir, string name, string localFile, bool readOnly)
 {
     DropBoxObjectMetadata file = _fileStore.CreateFile(CombinePaths(dir.Path, name), localFile, 5);
     DropBoxObjectHandler handler = new DropBoxObjectHandler(file);
     return new FileSystemFile(dir.Session, dir.Path, name, handler);
 }
Esempio n. 25
0
        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
Esempio n. 26
0
        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 && !NFX.Parsing.Utils.MatchPattern(fname, nameIncludePattern)) continue;
               if (nameExcludePattern!=null && NFX.Parsing.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++;
            }
        }