-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added hash only mode for compairing files. Fixed verbose logging. #13
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,6 +65,17 @@ public KuduSync(KuduSyncOptions options, Logger logger) | |
{ | ||
_to = Path.Combine(_to, _targetSubFolder); | ||
} | ||
|
||
if (_options.HashOnly) | ||
{ | ||
_logger.Log("Hash only mode ON"); | ||
} | ||
|
||
if (_options.Verbose) | ||
{ | ||
_logger.Log("Verbose logging ON"); | ||
} | ||
|
||
} | ||
|
||
private bool TryCleanupToBeDeletedDirectory() | ||
|
@@ -121,13 +132,12 @@ public void Run() | |
_nextManifest.SaveManifestFile(); | ||
|
||
TryCleanupToBeDeletedDirectory(); | ||
|
||
_logger.Log("Kudusync.NET Complete"); | ||
} | ||
|
||
private void SmartCopy(string sourcePath, | ||
string destinationPath, | ||
string targetSubFolder, | ||
DirectoryInfoBase sourceDirectory, | ||
DirectoryInfoBase destinationDirectory) | ||
//Main method | ||
private void SmartCopy(string sourcePath,string destinationPath,string targetSubFolder,DirectoryInfoBase sourceDirectory,DirectoryInfoBase destinationDirectory) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid unnecessary formatting changes that don't directly relate to the PR |
||
{ | ||
if (IgnorePath(sourceDirectory)) | ||
{ | ||
|
@@ -165,6 +175,7 @@ private void SmartCopy(string sourcePath, | |
|
||
// 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); | ||
|
@@ -184,26 +195,44 @@ private void SmartCopy(string sourcePath, | |
// 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; | ||
} | ||
|
||
var details = FileSystemHelpers.GetRelativePath(sourcePath, sourceFile.FullName) + (_options.CopyMetaData ? " " + ShorthandAttributes(sourceFile) : String.Empty); | ||
|
||
string path = FileSystemHelpers.GetDestinationPath(sourcePath, destinationPath, sourceFile); | ||
|
||
var details = FileSystemHelpers.GetRelativePath(sourcePath, sourceFile.FullName) + (_options.CopyMetaData ? " " + ShorthandAttributes(sourceFile) : String.Empty); | ||
switch (_options.HashOnly) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not use a simple 'if' statement instead of a |
||
{ | ||
case true: //behaviour added by JWC on 8/11/2016 | ||
if (destFilesLookup.TryGetValue(sourceFile.Name, out targetFile) && sourceFile.ComputeSha256() == targetFile.ComputeSha256()) //if destination contins file, and the hash matched | ||
{ | ||
if(_options.Verbose) | ||
_logger.Log("Hash match on {0}, will not copy", details); | ||
//move to next iteration if file the same | ||
continue; | ||
} | ||
break; | ||
case false: | ||
if (destFilesLookup.TryGetValue(sourceFile.Name, out targetFile) && sourceFile.LastWriteTimeUtc == targetFile.LastWriteTimeUtc) //if destination contains file, and the time matches | ||
{ | ||
//move to next iteration if file the same | ||
continue; | ||
} | ||
break; | ||
} | ||
|
||
//if file is not the same, the code below executes | ||
|
||
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())) | ||
{ | ||
// If current file is web.config check the content sha256. | ||
|
||
//if (!destFilesLookup.TryGetValue(sourceFile.Name, out targetFile) && !sourceFile.ComputeSha256().Equals(targetFile.ComputeSha256())) //if destination does not contain file OR the hash matches | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Clean up commented out code |
||
//{ | ||
// 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; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,15 +39,18 @@ public class KuduSyncOptions : CommandLineOptionsBase | |
[Option("q", "quiet", Required = false, HelpText = "No logging")] | ||
public bool Quiet { get; set; } | ||
|
||
[Option("v", "verbose", Required = false, HelpText = "Verbose logging with maximum number of output lines")] | ||
public int? Verbose { get; set; } | ||
[Option("v", "verbose", DefaultValue = false, Required = false, HelpText = "Verbose logging with maximum number of output lines")] | ||
public bool Verbose { get; set; } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That looks like a breaking change, since it used to represent the number of lines. Might be best to handle logging changes in a separate PR and keep this one focused on hash |
||
|
||
[Option("w", "whatIf", Required = false, HelpText = "Only log without actual copy/remove of files")] | ||
public bool WhatIf { get; set; } | ||
|
||
[Option("", "perf", Required = false, HelpText = "Print out the time it took to complete KuduSync operation")] | ||
public bool Perf { get; set; } | ||
|
||
[Option("h", "hashOnly", DefaultValue = false, Required = false, HelpText = "Compare files by contents only using SHA256")] | ||
public bool HashOnly { get; set; } | ||
|
||
[HelpOption] | ||
public string GetUsage() | ||
{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given non-security related scenario, isn't the existing Sha1 method sufficient?