Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit 3cf8660

Browse files
Adding functionality to skip the contents of a file when generating an MD5
This gives us a much faster test for the existence of files and not their contents
1 parent d52f0f6 commit 3cf8660

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/GitHub.Api/Extensions/FileSystemExtensions.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public static string CalculateFileMD5(this IFileSystem fileSystem, string file)
2222
return BitConverter.ToString(computeHash).Replace("-", string.Empty).ToLower();
2323
}
2424

25-
public static string CalculateFolderMD5(this IFileSystem fileSystem, string path)
25+
public static string CalculateFolderMD5(this IFileSystem fileSystem, string path, bool includeContents = true)
2626
{
2727
//https://stackoverflow.com/questions/3625658/creating-hash-for-folder
2828

@@ -39,9 +39,12 @@ public static string CalculateFolderMD5(this IFileSystem fileSystem, string path
3939
var pathBytes = Encoding.UTF8.GetBytes(relativeFilePath);
4040
md5.TransformBlock(pathBytes, 0, pathBytes.Length, pathBytes, 0);
4141

42-
// hash contents
43-
var contentBytes = File.ReadAllBytes(filePath);
44-
md5.TransformBlock(contentBytes, 0, contentBytes.Length, contentBytes, 0);
42+
if (includeContents)
43+
{
44+
// hash contents
45+
var contentBytes = File.ReadAllBytes(filePath);
46+
md5.TransformBlock(contentBytes, 0, contentBytes.Length, contentBytes, 0);
47+
}
4548
}
4649

4750
//Handles empty filePaths case

0 commit comments

Comments
 (0)