public void MirrorFolders(string localPath, int retries) { foreach (Tuple <string, List <File> > mirrorItem in MirrorsToFiles) { if (VaultEagle.VaultUtils.HandleNetworkErrors(() => System.IO.Directory.Exists(GetLocalFolder(mirrorItem.Item1, localPath)), retries)) { foreach (System.IO.FileInfo file in new System.IO.DirectoryInfo(GetLocalFolder(mirrorItem.Item1, localPath)).GetFiles()) { if (!mirrorItem.Item2.Any(i => i.Name.Equals(file.Name, StringComparison.InvariantCultureIgnoreCase))) { if (VaultEagle.VaultUtils.HandleNetworkErrors(() => System.IO.File.Exists(file.FullName), retries)) { VaultEagle.VaultCommunication.DeleteFileWithRetries(file.FullName, retries); } } } foreach (System.IO.DirectoryInfo directory in new System.IO.DirectoryInfo(GetLocalFolder(mirrorItem.Item1, localPath)).GetDirectories()) { if (!MirrorsToFiles.Any(i => GetLocalFolder(i.Item1, localPath).Equals(directory.FullName, StringComparison.InvariantCultureIgnoreCase))) { if (VaultEagle.VaultUtils.HandleNetworkErrors(() => System.IO.Directory.Exists(directory.FullName), retries)) { VaultEagle.VaultCommunication.DeleteFolder(directory.FullName, retries); } } } } } }
/****************************************************************************************************************************/ /****************************************************************************************************************************/ private void UpdateMirrorToFiles(string vaultRoot) { //string localRoot = GetLocalFolder(VaultPath, vaultRoot); List <string> emptyMirrorFolders = new List <string>(); foreach (Tuple <string, List <File> > mirrorFolders in MirrorsToFiles) { string folderName = /*GetLocalFolder(*/ mirrorFolders.Item1 /*, vaultRoot)*/; while (true) { if (!(MirrorsToFiles.Exists(t => folderName.Equals(t.Item1))) && (folderName.Length > VaultPath.Length) && !emptyMirrorFolders.Contains(folderName)) { emptyMirrorFolders.Add(folderName); } folderName = System.IO.Path.GetDirectoryName(folderName).Replace("\\", "/"); if (String.IsNullOrWhiteSpace(folderName)) { break; } } } foreach (string emptyMirrorFolder in emptyMirrorFolders) { MirrorsToFiles.Add(new Tuple <string, List <File> >(emptyMirrorFolder, new List <File>() { })); } }
public Model.DataStructures.DownloadItem[] GetFilesAndPathsForItem(Connection connection, List <Tuple <FileFolder, Option <string> > > fileAndFolders, List <File> addedFiles, string vaultRoot, bool allowChildren, int networkRetries) { List <string> skipFolder = new List <string>(); VaultEagle.VaultCommunication com = new VaultEagle.VaultCommunication(); com.InitializeFromConnection(connection); // List<Tuple<File, string, bool, bool>> filesAndPaths = new List<Tuple<File, string, bool, bool>>(); List <Model.DataStructures.DownloadItem> filesToDownload = new List <Model.DataStructures.DownloadItem>(); foreach (Tuple <FileFolder, Option <string> > fileAndFolderComponent in fileAndFolders) { FileFolder fileAndFolder = fileAndFolderComponent.Item1; foreach (string fp in SkipFolders) { if ((!skipFolder.Contains(fileAndFolder.Folder.FullName)) && (fileAndFolder.Folder.Cat.CatName.Equals(fp))) { skipFolder.Add(fileAndFolder.Folder.FullName); } } if ((AbhereSynchronizationRules(fileAndFolder, Recursive, allowChildren)) && (!skipFolder.Contains(fileAndFolder.Folder.FullName))) { if ((Mirrors.Where(m => fileAndFolder.Folder.FullName.ToLower().Contains(m.ToLower())).Count() > 0) && !(RecursiveMirrors.Where(m => fileAndFolder.Folder.FullName.Equals(m, StringComparison.InvariantCultureIgnoreCase)).Count() == 1)) { RecursiveMirrors.Add(fileAndFolder.Folder.FullName); MirrorsToFiles.Add(new Tuple <string, List <File> >(fileAndFolder.Folder.FullName, new List <File>())); } foreach (Tuple <string, List <File> > mirrorItem in MirrorsToFiles) { if (mirrorItem.Item1.Equals(fileAndFolder.Folder.FullName, StringComparison.InvariantCultureIgnoreCase)) { mirrorItem.Item2.Add(fileAndFolder.File); } } string localFilePath = GetLocalFolder(fileAndFolder.Folder.FullName + "/" + fileAndFolder.File.Name, vaultRoot); // if (System.IO.Path. string localPath = System.IO.Path.GetDirectoryName(localFilePath); File file = null; if ((DownloadOnState.Count > 0) /* && (DownloadOnState.Get().Equals("Released", StringComparison.InvariantCultureIgnoreCase))*/) { File releasedFile = null; VaultEagle.VaultUtils.FileState state = VaultEagle.VaultUtils.GetLastRelevantFileState(fileAndFolder.File.VerNum, fileAndFolder.File.MasterId, connection, ref releasedFile, DownloadOnState, InvalidStates.ToList()); if (state == VaultEagle.VaultUtils.FileState.Ok) { file = releasedFile; } else if (state == VaultEagle.VaultUtils.FileState.Obsolete) { DeleteFile(localFilePath, networkRetries); //Delete file? } } else { file = fileAndFolder.File; } if (file == null) { continue; } if (VaultEagle.VaultUtils.HandleNetworkErrors(() => System.IO.File.Exists(localPath + "/" + fileAndFolder.File.Name), networkRetries)) { if (file != null) { if (Force || file.Cksum != VaultEagle.VaultUtils.HandleNetworkErrors(() => { return(VaultEagle.VaultCommunication.CalculateCrc32(localPath + "/" + fileAndFolder.File.Name)); }, networkRetries)) { if (!addedFiles.Contains(file)) { if (DownloadToTemp) { bool run = RunFile(file); TempFilesAndFinalPath.Add(new Tuple <string, string>(System.IO.Path.Combine(TempPath, file.Name), System.IO.Path.Combine(localPath, file.Name))); //filesAndPaths.Add(new Tuple<File, string, bool, bool>(PatternsToSynchronize.Count() == 1 && PatternsToSynchronize[0].Equals("/") ? null : file, TempPath, Writable, run)); filesToDownload.Add(GetDownloadItem(TempPath, file, Writable, run, fileAndFolderComponent.Item2)); } else { bool run = RunFile(file); //filesAndPaths.Add(new Tuple<File, string, bool, bool>(PatternsToSynchronize.Count() == 1 && PatternsToSynchronize[0].Equals("/") ? null : file, localPath, Writable, run)); filesToDownload.Add(GetDownloadItem(localPath, file, Writable, run, fileAndFolderComponent.Item2)); } addedFiles.Add(file); } } } } else if (file != null) { if (!addedFiles.Contains(file)) { if (DownloadToTemp) { bool run = RunFile(file); TempFilesAndFinalPath.Add(new Tuple <string, string>(System.IO.Path.Combine(TempPath, file.Name), System.IO.Path.Combine(localPath, file.Name))); // filesAndPaths.Add(new Tuple<File, string, bool, bool>(PatternsToSynchronize.Count() == 1 && PatternsToSynchronize[0].Equals("/") ? null : file, TempPath, Writable, run)); filesToDownload.Add(GetDownloadItem(TempPath, file, Writable, run, fileAndFolderComponent.Item2)); } else { bool run = RunFile(file); //filesAndPaths.Add(new Tuple<File, string, bool, bool>(PatternsToSynchronize.Count() == 1 && PatternsToSynchronize[0].Equals("/") ? null : file, localPath, Writable, run)); filesToDownload.Add(GetDownloadItem(localPath, file, Writable, run, fileAndFolderComponent.Item2)); } addedFiles.Add(file); } } } else if (!Recursive && fileAndFolder.Folder.FullName.Equals(VaultPath)) { filesToDownload.Add(new Model.DataStructures.DownloadFolder(GetLocalFolder(VaultPath, vaultRoot))); } //filesAndPaths.Add(new Tuple<File, string, bool, bool>(null, GetLocalFolder(VaultPath, vaultRoot), false, false)); } UpdateMirrorToFiles(vaultRoot); return(filesToDownload.ToArray()); }