protected override Task <HttpResponseMessage> CreateDirectoryPutResponse(DirectoryInfoBase info, string localFilePath) { if (info != null && info.Exists) { // Return a conflict result return(base.CreateDirectoryPutResponse(info, localFilePath)); } try { info.Create(); } catch (IOException ex) { Tracer.TraceError(ex); HttpResponseMessage conflictDirectoryResponse = Request.CreateErrorResponse( HttpStatusCode.Conflict, Resources.VfsControllerBase_CannotDeleteDirectory); return(Task.FromResult(conflictDirectoryResponse)); } // Return 201 Created response HttpResponseMessage successFileResponse = Request.CreateResponse(HttpStatusCode.Created); return(Task.FromResult(successFileResponse)); }
protected Task <HttpResponseMessage> CreateDirectoryPutResponse(HttpRequest request, DirectoryInfoBase info, string localFilePath) { if (info != null && info.Exists) { // Return a conflict result var conflictDirectoryResponse = CreateResponse(HttpStatusCode.Conflict); return(Task.FromResult(conflictDirectoryResponse)); } try { info.Create(); } catch (IOException ex) { _logger.LogError(ex, ex.Message); HttpResponseMessage conflictDirectoryResponse = CreateResponse(HttpStatusCode.Conflict); return(Task.FromResult(conflictDirectoryResponse)); } // Return 201 Created response var successFileResponse = CreateResponse(HttpStatusCode.Created); return(Task.FromResult(successFileResponse)); }
protected override Task <IActionResult> CreateDirectoryPutResponse(DirectoryInfoBase info, string localFilePath) { if (info != null && info.Exists) { // Return a conflict result return(base.CreateDirectoryPutResponse(info, localFilePath)); } try { info.Create(); } catch (IOException ex) { Tracer.TraceError(ex); return(Task.FromResult((IActionResult)StatusCode(StatusCodes.Status409Conflict, Resources.VfsControllerBase_CannotDeleteDirectory))); } // Return 201 Created response return(Task.FromResult((IActionResult)StatusCode(StatusCodes.Status201Created))); }
internal static void Copy(string sourcePath, string destinationPath, DirectoryInfoBase sourceDirectory, DirectoryInfoBase destinationDirectory, Func <string, DirectoryInfoBase> createDirectoryInfo, bool skipScmFolder) { // Skip hidden directories and directories that begin with . if (skipScmFolder && IsSourceControlFolder(sourceDirectory)) { return; } if (!destinationDirectory.Exists) { destinationDirectory.Create(); } foreach (var sourceFile in sourceDirectory.GetFiles()) { string path = GetDestinationPath(sourcePath, destinationPath, sourceFile); sourceFile.CopyTo(path, overwrite: true); } var destDirectoryLookup = GetDirectories(destinationDirectory); foreach (var sourceSubDirectory in sourceDirectory.GetDirectories()) { DirectoryInfoBase targetSubDirectory; if (!destDirectoryLookup.TryGetValue(sourceSubDirectory.Name, out targetSubDirectory)) { string path = GetDestinationPath(sourcePath, destinationPath, sourceSubDirectory); targetSubDirectory = createDirectoryInfo(path); } Copy(sourcePath, destinationPath, sourceSubDirectory, targetSubDirectory, createDirectoryInfo, skipScmFolder); } }
private void SmartCopy(string sourcePath, string destinationPath, string targetSubFolder, DirectoryInfoBase sourceDirectory, DirectoryInfoBase destinationDirectory) { if (IgnorePath(sourceDirectory)) { return; } // No need to copy a directory to itself if (destinationPath == sourceDirectory.FullName) { return; } if (!destinationDirectory.Exists) { destinationDirectory.Create(); if (_options.CopyMetaData) { destinationDirectory.Attributes = sourceDirectory.Attributes; } } var destFilesLookup = FileSystemHelpers.GetFiles(destinationDirectory); var sourceFilesLookup = FileSystemHelpers.GetFiles(sourceDirectory); foreach (var destFile in destFilesLookup.Values) { if (IgnorePath(destFile)) { continue; } // If the file doesn't exist in the source, only delete if: // 1. We have no previous directory // 2. We have a previous directory and the file exists there // Trim the start destinationFilePath string previousPath = FileSystemHelpers.GetRelativePath(destinationPath, destFile.FullName); if (!sourceFilesLookup.ContainsKey(destFile.Name) && DoesPathExistsInManifest(previousPath, targetSubFolder)) { _logger.Log("Deleting file: '{0}'", previousPath); OperationManager.Attempt(() => SmartDeleteFile(destFile)); } } foreach (var sourceFile in sourceFilesLookup.Values) { if (IgnorePath(sourceFile)) { continue; } _nextManifest.AddPath(sourcePath, sourceFile.FullName, targetSubFolder); // if the file exists in the destination then only copy it again if it's // last write time is different than the same file in the source (only if it changed) FileInfoBase targetFile; if (destFilesLookup.TryGetValue(sourceFile.Name, out targetFile) && sourceFile.LastWriteTimeUtc == targetFile.LastWriteTimeUtc) { continue; } string path = FileSystemHelpers.GetDestinationPath(sourcePath, destinationPath, sourceFile); var details = FileSystemHelpers.GetRelativePath(sourcePath, sourceFile.FullName) + (_options.CopyMetaData ? " " + ShorthandAttributes(sourceFile) : String.Empty); if (sourceFile.IsWebConfig()) { // If current file is web.config check the content sha1. if (!destFilesLookup.TryGetValue(sourceFile.Name, out targetFile) || !sourceFile.ComputeSha1().Equals(targetFile.ComputeSha1())) { // Save the file path to copy later for copying web.config forces an appDomain // restart right away without respecting waitChangeNotification _filesToCopyLast.Add(Tuple.Create(sourceFile, path, details)); } continue; } // Otherwise, copy the file _logger.Log("Copying file: '{0}'", details); OperationManager.Attempt(() => SmartCopyFile(sourceFile, path)); } var sourceDirectoryLookup = FileSystemHelpers.GetDirectories(sourceDirectory); var destDirectoryLookup = FileSystemHelpers.GetDirectories(destinationDirectory); foreach (var destSubDirectory in destDirectoryLookup.Values) { // If the directory doesn't exist in the source, only delete if: // 1. We have no previous directory // 2. We have a previous directory and the file exists there if (!sourceDirectoryLookup.ContainsKey(destSubDirectory.Name)) { SmartDirectoryDelete(destSubDirectory, destinationPath, targetSubFolder); } } foreach (var sourceSubDirectory in sourceDirectoryLookup.Values) { DirectoryInfoBase targetSubDirectory; if (!destDirectoryLookup.TryGetValue(sourceSubDirectory.Name, out targetSubDirectory)) { string path = FileSystemHelpers.GetDestinationPath(sourcePath, destinationPath, sourceSubDirectory); targetSubDirectory = CreateDirectoryInfo(path); } _nextManifest.AddPath(sourcePath, sourceSubDirectory.FullName, targetSubFolder); // Sync all sub directories SmartCopy(sourcePath, destinationPath, targetSubFolder, sourceSubDirectory, targetSubDirectory); } }
internal static void SmartCopy(string sourcePath, string destinationPath, Func <string, bool> existsInPrevious, DirectoryInfoBase sourceDirectory, DirectoryInfoBase destinationDirectory, Func <string, DirectoryInfoBase> createDirectoryInfo) { // Skip source control folder if (FileSystemHelpers.IsSourceControlFolder(sourceDirectory)) { return; } if (!destinationDirectory.Exists) { destinationDirectory.Create(); } // var previousFilesLookup = GetFiles(previousDirectory); var destFilesLookup = FileSystemHelpers.GetFiles(destinationDirectory); var sourceFilesLookup = FileSystemHelpers.GetFiles(sourceDirectory); foreach (var destFile in destFilesLookup.Values) { // If the file doesn't exist in the source, only delete if: // 1. We have no previous directory // 2. We have a previous directory and the file exists there // Trim the start path string previousPath = destFile.FullName.Substring(destinationPath.Length).TrimStart('\\'); if (!sourceFilesLookup.ContainsKey(destFile.Name) && ((existsInPrevious == null) || (existsInPrevious != null && existsInPrevious(previousPath)))) { destFile.Delete(); } } foreach (var sourceFile in sourceFilesLookup.Values) { // Skip the .deployment file if (sourceFile.Name.Equals(DeploymentSettingsProvider.DeployConfigFile, StringComparison.OrdinalIgnoreCase)) { continue; } // if the file exists in the destination then only copy it again if it's // last write time is different than the same file in the source (only if it changed) FileInfoBase targetFile; if (destFilesLookup.TryGetValue(sourceFile.Name, out targetFile) && sourceFile.LastWriteTimeUtc == targetFile.LastWriteTimeUtc) { continue; } // Otherwise, copy the file string path = FileSystemHelpers.GetDestinationPath(sourcePath, destinationPath, sourceFile); OperationManager.Attempt(() => sourceFile.CopyTo(path, overwrite: true)); } var sourceDirectoryLookup = FileSystemHelpers.GetDirectories(sourceDirectory); var destDirectoryLookup = FileSystemHelpers.GetDirectories(destinationDirectory); foreach (var destSubDirectory in destDirectoryLookup.Values) { // If the directory doesn't exist in the source, only delete if: // 1. We have no previous directory // 2. We have a previous directory and the file exists there string previousPath = destSubDirectory.FullName.Substring(destinationPath.Length).TrimStart('\\'); if (!sourceDirectoryLookup.ContainsKey(destSubDirectory.Name) && ((existsInPrevious == null) || (existsInPrevious != null && existsInPrevious(previousPath)))) { destSubDirectory.Delete(recursive: true); } } foreach (var sourceSubDirectory in sourceDirectoryLookup.Values) { DirectoryInfoBase targetSubDirectory; if (!destDirectoryLookup.TryGetValue(sourceSubDirectory.Name, out targetSubDirectory)) { string path = FileSystemHelpers.GetDestinationPath(sourcePath, destinationPath, sourceSubDirectory); targetSubDirectory = createDirectoryInfo(path); } // Sync all sub directories SmartCopy(sourcePath, destinationPath, existsInPrevious, sourceSubDirectory, targetSubDirectory, createDirectoryInfo); } }
private void SmartCopy(string sourcePath, string destinationPath, DirectoryInfoBase sourceDirectory, DirectoryInfoBase destinationDirectory) { if (IgnorePath(sourceDirectory)) { return; } // No need to copy a directory to itself if (destinationPath == sourceDirectory.FullName) { return; } if (!destinationDirectory.Exists) { destinationDirectory.Create(); if (_options.CopyMetaData) { destinationDirectory.Attributes = sourceDirectory.Attributes; } } var destFilesLookup = FileSystemHelpers.GetFiles(destinationDirectory); var sourceFilesLookup = FileSystemHelpers.GetFiles(sourceDirectory); foreach (var destFile in destFilesLookup.Values) { if (IgnorePath(destFile)) { continue; } // If the file doesn't exist in the source, only delete if: // 1. We have no previous directory // 2. We have a previous directory and the file exists there // Trim the start path string previousPath = FileSystemHelpers.GetRelativePath(destinationPath, destFile.FullName); if (!sourceFilesLookup.ContainsKey(destFile.Name) && DoesPathExistsInManifest(previousPath)) { _logger.Log("Deleting file: '{0}'", previousPath); OperationManager.Attempt(() => destFile.Delete()); } } foreach (var sourceFile in sourceFilesLookup.Values) { if (IgnorePath(sourceFile)) { continue; } _nextManifest.AddPath(sourcePath, sourceFile.FullName); // if the file exists in the destination then only copy it again if it's // last write time is different than the same file in the source (only if it changed) FileInfoBase targetFile; if (destFilesLookup.TryGetValue(sourceFile.Name, out targetFile) && sourceFile.LastWriteTimeUtc == targetFile.LastWriteTimeUtc) { continue; } // Otherwise, copy the file string path = FileSystemHelpers.GetDestinationPath(sourcePath, destinationPath, sourceFile); var details = FileSystemHelpers.GetRelativePath(sourcePath, sourceFile.FullName) + (_options.CopyMetaData ? " " + ShorthandAttributes(sourceFile) : String.Empty); _logger.Log("Copying file: '{0}'", details); OperationManager.Attempt(() => SmartCopyFile(sourceFile, path)); } var sourceDirectoryLookup = FileSystemHelpers.GetDirectories(sourceDirectory); var destDirectoryLookup = FileSystemHelpers.GetDirectories(destinationDirectory); foreach (var destSubDirectory in destDirectoryLookup.Values) { // If the directory doesn't exist in the source, only delete if: // 1. We have no previous directory // 2. We have a previous directory and the file exists there if (!sourceDirectoryLookup.ContainsKey(destSubDirectory.Name)) { SmartDirectoryDelete(destSubDirectory, destinationPath); } } foreach (var sourceSubDirectory in sourceDirectoryLookup.Values) { DirectoryInfoBase targetSubDirectory; if (!destDirectoryLookup.TryGetValue(sourceSubDirectory.Name, out targetSubDirectory)) { string path = FileSystemHelpers.GetDestinationPath(sourcePath, destinationPath, sourceSubDirectory); targetSubDirectory = CreateDirectoryInfo(path); } _nextManifest.AddPath(sourcePath, sourceSubDirectory.FullName); // Sync all sub directories SmartCopy(sourcePath, destinationPath, sourceSubDirectory, targetSubDirectory); } }