private void addFile(int folderId, TreeTraverser.FileEntry file) { string fileMD5 = file.GetMD5((percent) => { this.reportBackupAction(new BackupActionItem(null, file.RelPath, BackupActionEntity.File, BackupActionOperation.Hash, null, percent)); return(!this.Cancelled); }); if (this.Cancelled) { return; } foreach (BackendBase backend in this.backends) { // Search for alternates if (this.createFromAlternate(file, fileMD5, false, backend)) { continue; } this.reportBackupAction(new BackupActionItem(null, file.RelPath, BackupActionEntity.File, BackupActionOperation.Add, backend.Name)); backend.CreateFile(file.RelPath, file.FullPath, file.LastModified, fileMD5, file.Attributes); this.Logger.Info("{0}: Added file: {1}", backend.Name, file.RelPath); } this.fileDatabase.AddFile(folderId, file.RelPath, file.LastModified, fileMD5); }
private void updatefile(int fileId, TreeTraverser.FileEntry file, string remoteMD5) { this.reportBackupAction(new BackupActionItem(null, file.RelPath, BackupActionEntity.File, BackupActionOperation.Hash)); // Only copy if the file has actually changed string fileMD5 = file.GetMD5((percent) => { this.reportBackupAction(new BackupActionItem(null, file.RelPath, BackupActionEntity.File, BackupActionOperation.Hash, null, percent)); return(!this.Cancelled); }); if (this.Cancelled) { return; } if (remoteMD5 == fileMD5) { foreach (BackendBase backend in this.backends) { backend.TouchFile(file.RelPath, file.LastModified); } //this.Logger.Info("File mtime changed, but file unchanged. Touching: {0}", file); return; } foreach (BackendBase backend in this.backends) { if (this.createFromAlternate(file, fileMD5, true, backend)) { continue; } this.reportBackupAction(new BackupActionItem(null, file.RelPath, BackupActionEntity.File, BackupActionOperation.Update, backend.Name)); if (backend.CreateFile(file.RelPath, file.FullPath, file.LastModified, fileMD5, file.Attributes)) { this.Logger.Info("{0}: Updated file: {1}", backend.Name, file.RelPath); } else { this.Logger.Info("{0}: Skipped file {1} (mtime changed but file up-to-date)", backend.Name, file.RelPath); } } // But update the last modified time either way this.fileDatabase.UpdateFile(fileId, file.LastModified, fileMD5); }