コード例 #1
0
ファイル: FsSenderChange.cs プロジェクト: 364988343/DevSync
 public static FsSenderChange CreateChange(FsEntry fsEntry)
 {
     return(new FsSenderChange(FsChangeType.Change, fsEntry.Path)
     {
         LastWriteTime = fsEntry.LastWriteTime,
         IsDirectory = fsEntry.IsDirectory,
     });
 }
コード例 #2
0
ファイル: FileMaskList.cs プロジェクト: lulzzz/DevSync
        protected StringBuilder MaskToRegex(string mask)
        {
            var re = new StringBuilder(Regex.Escape(FsEntry.NormalizePath(mask)))
                     // *
                     .Replace("\\*", "[^/]*")
                     // ?
                     .Replace("\\?", "[^/]");

            // slash in the beginning -> begin of string
            re.Insert(0, re[0] == '/' ? '^' : '/');

            // slash after mask
            if (re[re.Length - 1] != '/')
            {
                re.Append('/');
            }

            return(re);
        }
コード例 #3
0
 public bool Compare(FsEntry other)
 {
     // TODO: we don't compare dates for directories
     return(Path == other.Path && Length == other.Length && (IsDirectory || CompareDates(LastWriteTime, other.LastWriteTime)));
 }
コード例 #4
0
        public IEnumerable <FsEntry> ScanPath(DirectoryInfo directoryInfo, string relativePath = "")
        {
            IEnumerable <FileSystemInfo> fileSystemInfos = null;

            try
            {
                if (directoryInfo.Exists)
                {
                    fileSystemInfos = directoryInfo.EnumerateFileSystemInfos("*", new EnumerationOptions
                    {
                        ReturnSpecialDirectories = false,
                        // Skip symlinks
                        AttributesToSkip = FileAttributes.ReparsePoint
                    });
                }
            }
            catch (DirectoryNotFoundException)
            {
                // directory vanished during scan
            }
            catch (Exception ex)
            {
                _logger.Log($"Error scanning directory: {ex.Message}", LogLevel.Warning);
            }

            if (fileSystemInfos != null)
            {
                foreach (var fsInfo in fileSystemInfos)
                {
                    _cancellationToken?.ThrowIfCancellationRequested();

                    var path    = Path.Combine(relativePath, fsInfo.Name);
                    var fsEntry = FsEntry.Empty;

                    // skip excludes
                    if (!_excludeList.IsMatch(FsEntry.NormalizePath(path)))
                    {
                        // scan children
                        if (fsInfo is DirectoryInfo childDirectoryInfo)
                        {
                            foreach (var entry in ScanPath(childDirectoryInfo, path))
                            {
                                yield return(entry);
                            }
                        }

                        try
                        {
                            fsEntry = FsEntry.FromFsInfo(path, fsInfo, _withInfo);
                        }
                        catch (DirectoryNotFoundException)
                        {
                            // directory vanished during scan
                        }
                        catch (Exception ex)
                        {
                            _logger.Log($"Error scanning directory: {ex.Message}", LogLevel.Warning);
                        }

                        if (!fsEntry.IsEmpty)
                        {
                            yield return(fsEntry);
                        }
                    }
                }
            }
        }