Skip to content

Commit

Permalink
(GH-476) Verbose log file operations / checksum
Browse files Browse the repository at this point in the history
Any file system operation is probably better served as a verbose log as
it could be quite a bit of information being passed around.

For checksumming files, it is definitely a verbose set of information -
definitely not something we want to overload users with unless they opt
into seeing the information.
  • Loading branch information
ferventcoder committed Jan 21, 2016
1 parent fe640fb commit 381a492
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
3 changes: 2 additions & 1 deletion src/chocolatey/infrastructure.app/services/FilesService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ namespace chocolatey.infrastructure.app.services
using domain;
using filesystem;
using infrastructure.services;
using logging;
using results;

public sealed class FilesService : IFilesService
Expand Down Expand Up @@ -127,7 +128,7 @@ public PackageFiles capture_package_files(string directory, ChocolateyConfigurat
public PackageFile get_package_file(string file)
{
var hash = _hashProvider.hash_file(file);
this.Log().Debug(() => " Found '{0}'{1} with checksum '{2}'".format_with(file, Environment.NewLine, hash));
this.Log().Debug(ChocolateyLoggers.Verbose,() => " Found '{0}'{1} with checksum '{2}'".format_with(file, Environment.NewLine, hash));

return new PackageFile { Path = file, Checksum = hash };
}
Expand Down
35 changes: 18 additions & 17 deletions src/chocolatey/infrastructure/filesystem/DotNetFileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ namespace chocolatey.infrastructure.filesystem
using System.Threading;
using adapters;
using app;
using logging;
using platforms;
using tolerance;
using Assembly = adapters.Assembly;
Expand Down Expand Up @@ -221,7 +222,7 @@ public bool is_system_file(FileInfo file)
}
else
{
this.Log().Debug(() => "File \"{0}\" is a system file.".format_with(file.FullName));
this.Log().Debug(ChocolateyLoggers.Verbose, () => "File \"{0}\" is a system file.".format_with(file.FullName));
}

return isSystemFile;
Expand All @@ -238,7 +239,7 @@ public bool is_readonly_file(FileInfo file)
}
else
{
this.Log().Debug(() => "File \"{0}\" is a readonly file.".format_with(file.FullName));
this.Log().Debug(ChocolateyLoggers.Verbose, () => "File \"{0}\" is a readonly file.".format_with(file.FullName));
}

return isReadOnlyFile;
Expand All @@ -255,7 +256,7 @@ public bool is_hidden_file(FileInfo file)
}
else
{
this.Log().Debug(() => "File \"{0}\" is a hidden file.".format_with(file.FullName));
this.Log().Debug(ChocolateyLoggers.Verbose, () => "File \"{0}\" is a hidden file.".format_with(file.FullName));
}

return isHiddenFile;
Expand All @@ -264,7 +265,7 @@ public bool is_hidden_file(FileInfo file)
public bool is_encrypted_file(FileInfo file)
{
bool isEncrypted = ((file.Attributes & FileAttributes.Encrypted) == FileAttributes.Encrypted);
this.Log().Debug(() => "Is file \"{0}\" an encrypted file? {1}".format_with(file.FullName, isEncrypted.to_string()));
this.Log().Debug(ChocolateyLoggers.Verbose, () => "Is file \"{0}\" an encrypted file? {1}".format_with(file.FullName, isEncrypted.to_string()));
return isEncrypted;
}

Expand All @@ -283,7 +284,7 @@ public void move_file(string filePath, string newFilePath)

public void copy_file(string sourceFilePath, string destinationFilePath, bool overwriteExisting)
{
this.Log().Debug(() => "Attempting to copy \"{0}\"{1} to \"{2}\".".format_with(sourceFilePath, Environment.NewLine, destinationFilePath));
this.Log().Debug(ChocolateyLoggers.Verbose, () => "Attempting to copy \"{0}\"{1} to \"{2}\".".format_with(sourceFilePath, Environment.NewLine, destinationFilePath));
create_directory_if_not_exists(get_directory_name(destinationFilePath), ignoreError: true);

allow_retries(() => File.Copy(sourceFilePath, destinationFilePath, overwriteExisting));
Expand All @@ -297,7 +298,7 @@ public bool copy_file_unsafe(string sourceFilePath, string destinationFilePath,
return true;
}

this.Log().Debug(() => "Attempting to copy from \"{0}\" to \"{1}\".".format_with(sourceFilePath, destinationFilePath));
this.Log().Debug(ChocolateyLoggers.Verbose, () => "Attempting to copy from \"{0}\" to \"{1}\".".format_with(sourceFilePath, destinationFilePath));
create_directory_if_not_exists(get_directory_name(destinationFilePath), ignoreError: true);

//Private Declare Function apiCopyFile Lib "kernel32" Alias "CopyFileA" _
Expand Down Expand Up @@ -329,7 +330,7 @@ _In_ BOOL bFailIfExists

public void delete_file(string filePath)
{
this.Log().Debug(() => "Attempting to delete file \"{0}\".".format_with(filePath));
this.Log().Debug(ChocolateyLoggers.Verbose, () => "Attempting to delete file \"{0}\".".format_with(filePath));
if (file_exists(filePath))
{
allow_retries(() => File.Delete(filePath));
Expand Down Expand Up @@ -433,7 +434,7 @@ public DirectoryInfo get_directory_info_from_file_path(string filePath)

public void create_directory(string directoryPath)
{
this.Log().Debug(() => "Attempting to create directory \"{0}\".".format_with(get_full_path(directoryPath)));
this.Log().Debug(ChocolateyLoggers.Verbose, () => "Attempting to create directory \"{0}\".".format_with(get_full_path(directoryPath)));
allow_retries(() => Directory.CreateDirectory(directoryPath));
}

Expand All @@ -444,12 +445,12 @@ public void move_directory(string directoryPath, string newDirectoryPath)

try
{
this.Log().Debug("Moving '{0}'{1} to '{2}'".format_with(directoryPath, Environment.NewLine, newDirectoryPath));
this.Log().Debug(ChocolateyLoggers.Verbose, "Moving '{0}'{1} to '{2}'".format_with(directoryPath, Environment.NewLine, newDirectoryPath));
allow_retries(() => Directory.Move(directoryPath, newDirectoryPath));
}
catch (Exception ex)
{
this.Log().Warn("Move failed with message:{0} {1}{0} Attempting backup move method.".format_with(Environment.NewLine, ex.Message));
this.Log().Warn(ChocolateyLoggers.Verbose, "Move failed with message:{0} {1}{0} Attempting backup move method.".format_with(Environment.NewLine, ex.Message));

create_directory_if_not_exists(newDirectoryPath, ignoreError: true);
foreach (var file in get_files(directoryPath, "*.*", SearchOption.AllDirectories).or_empty_list_if_null())
Expand All @@ -458,7 +459,7 @@ public void move_directory(string directoryPath, string newDirectoryPath)
if (file_exists(destinationFile)) delete_file(destinationFile);

create_directory_if_not_exists(get_directory_name(destinationFile), ignoreError: true);
this.Log().Debug("Moving '{0}'{1} to '{2}'".format_with(file, Environment.NewLine, destinationFile));
this.Log().Debug(ChocolateyLoggers.Verbose, "Moving '{0}'{1} to '{2}'".format_with(file, Environment.NewLine, destinationFile));
move_file(file, destinationFile);
}

Expand All @@ -477,7 +478,7 @@ public void copy_directory(string sourceDirectoryPath, string destinationDirecto
{
var destinationFile = file.Replace(sourceDirectoryPath, destinationDirectoryPath);
create_directory_if_not_exists(get_directory_name(destinationFile), ignoreError: true);
//this.Log().Debug("Copying '{0}' {1} to '{2}'".format_with(file, Environment.NewLine, destinationFile));
//this.Log().Debug(ChocolateyLoggers.Verbose, "Copying '{0}' {1} to '{2}'".format_with(file, Environment.NewLine, destinationFile));
copy_file(file, destinationFile, overwriteExisting);
}

Expand Down Expand Up @@ -531,7 +532,7 @@ public void delete_directory(string directoryPath, bool recursive, bool override
}
}

this.Log().Debug(() => "Attempting to delete directory \"{0}\".".format_with(get_full_path(directoryPath)));
this.Log().Debug(ChocolateyLoggers.Verbose, () => "Attempting to delete directory \"{0}\".".format_with(get_full_path(directoryPath)));
allow_retries(() => Directory.Delete(directoryPath, recursive));
}

Expand All @@ -557,7 +558,7 @@ public void ensure_file_attribute_set(string path, FileAttributes attributes)
var directoryInfo = get_directory_info_for(path);
if ((directoryInfo.Attributes & attributes) != attributes)
{
this.Log().Debug(() => "Adding '{0}' attribute(s) to '{1}'.".format_with(attributes.to_string(), path));
this.Log().Debug(ChocolateyLoggers.Verbose, () => "Adding '{0}' attribute(s) to '{1}'.".format_with(attributes.to_string(), path));
directoryInfo.Attributes |= attributes;
}
}
Expand All @@ -566,7 +567,7 @@ public void ensure_file_attribute_set(string path, FileAttributes attributes)
var fileInfo = get_file_info_for(path);
if ((fileInfo.Attributes & attributes) != attributes)
{
this.Log().Debug(() => "Adding '{0}' attribute(s) to '{1}'.".format_with(attributes.to_string(), path));
this.Log().Debug(ChocolateyLoggers.Verbose, () => "Adding '{0}' attribute(s) to '{1}'.".format_with(attributes.to_string(), path));
fileInfo.Attributes |= attributes;
}
}
Expand All @@ -579,7 +580,7 @@ public void ensure_file_attribute_removed(string path, FileAttributes attributes
var directoryInfo = get_directory_info_for(path);
if ((directoryInfo.Attributes & attributes) == attributes)
{
this.Log().Debug(() => "Removing '{0}' attribute(s) from '{1}'.".format_with(attributes.to_string(), path));
this.Log().Debug(ChocolateyLoggers.Verbose, () => "Removing '{0}' attribute(s) from '{1}'.".format_with(attributes.to_string(), path));
directoryInfo.Attributes &= ~attributes;
}
}
Expand All @@ -588,7 +589,7 @@ public void ensure_file_attribute_removed(string path, FileAttributes attributes
var fileInfo = get_file_info_for(path);
if ((fileInfo.Attributes & attributes) == attributes)
{
this.Log().Debug(() => "Removing '{0}' attribute(s) from '{1}'.".format_with(attributes.to_string(), path));
this.Log().Debug(ChocolateyLoggers.Verbose, () => "Removing '{0}' attribute(s) from '{1}'.".format_with(attributes.to_string(), path));
fileInfo.Attributes &= ~attributes;
}
}
Expand Down

0 comments on commit 381a492

Please sign in to comment.