public string FindByLengthAndRelativePath(FileInfoEx fInfoEx) { var fileFromPrevBackup = _prevBackupFilesLookupBypathByLength.TryGetValue(fInfoEx.FileName, out var byHash) ? byHash.TryGetValue(fInfoEx.FileInfo.Length, out var file) ? file : null : null; string existingFile; if (fileFromPrevBackup != null) { existingFile = fileFromPrevBackup.Item2.AbsolutePath + fileFromPrevBackup.Item1.Path; } else { existingFile = _currentBkp.FindFile(fInfoEx)?.Path; if (existingFile != null) { existingFile = _currentBkp.AbsolutePath + existingFile; } } return(existingFile); }
public BackupFileInfo FindFile(FileInfoEx fInfoEx) { if (_filesLookup.TryGetValue(fInfoEx.FileInfo.Length, out var byHash)) { return(byHash.TryGetValue(fInfoEx.FastHashStr, out var file) ? file : null); } return(null); }
public BackupFileModel(string fullFileName, string relativeFileName) { if (string.IsNullOrEmpty(fullFileName)) { throw new Exception("File path can not be empty"); } FileInfo = new FileInfoEx(fullFileName); RelativePathWin = PathHelpers.NormalizePathWin(relativeFileName).TrimStart('\\', '/'); RelativePathUnix = PathHelpers.NormalizePathUnix(relativeFileName).TrimStart('\\', '/'); RelativeDirectoryNameWin = PathHelpers.NormalizePathWin(Path.GetDirectoryName(relativeFileName)).TrimStart('\\', '/'); RelativeDirectoryNameUnix = PathHelpers.NormalizePathUnix(Path.GetDirectoryName(relativeFileName)).TrimStart('\\', '/'); }
public void CheckIntegrity() { if (!Directory.Exists(AbsolutePath)) { throw new InvalidOperationException("Backup directory not found"); } foreach (var f in _files) { var fileName = AbsolutePath + f.Path; if (!File.Exists(fileName)) { throw new InvalidOperationException("File was removed"); } var fi = new FileInfoEx(fileName); if (f.Hash != fi.FastHashStr) { throw new InvalidOperationException("File corrupt"); } } }