Skip to content

Commit 0ae343e

Browse files
committed
Fix #4
1 parent 2dbf23d commit 0ae343e

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

src/UnturnedRedistUpdateTool/RedistUpdater.cs

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,10 @@ public RedistUpdater(string managedDir, string redistPath, List<string> publiciz
2727
if (managedFiles.Length == 0)
2828
throw new InvalidOperationException($"{_managedDir} is empty");
2929

30-
// If updateFiles is empty, process all files
31-
// If updateFiles has items, only process those files
3230
var filesToProcess = _updateFiles.Count > 0
3331
? managedFiles.Where(f => _updateFiles.Contains(f.Name)).ToArray()
3432
: managedFiles;
3533

36-
// Only validate if updateFiles has items
3734
if (_updateFiles.Count > 0)
3835
{
3936
var existingFileNames = managedFiles.Select(f => f.Name).ToHashSet();
@@ -69,8 +66,30 @@ public RedistUpdater(string managedDir, string redistPath, List<string> publiciz
6966
}
7067
updatedFiles[managedFilePath] = redistFilePath;
7168
}
69+
70+
var completeManifest = await CreateCompleteManifestAsync();
7271
var manifestPath = Path.Combine(_redistPath, "manifest.sha256.json");
73-
await File.WriteAllTextAsync(manifestPath, JsonSerializer.Serialize(manifests, ManifestJsonSerializerOptions));
72+
await File.WriteAllTextAsync(manifestPath, JsonSerializer.Serialize(completeManifest, ManifestJsonSerializerOptions));
7473
return (updatedFiles, manifests);
7574
}
75+
76+
private Task<Dictionary<string, string>> CreateCompleteManifestAsync()
77+
{
78+
var completeManifest = new Dictionary<string, string>();
79+
var redistDirectory = new DirectoryInfo(_redistPath);
80+
81+
// Only include files that are specified in updateFiles list
82+
// These are the files that can actually be updated from Unturned
83+
var relevantFiles = redistDirectory.GetFiles()
84+
.Where(f => f.Name != "manifest.sha256.json" && _updateFiles.Contains(f.Name))
85+
.ToArray();
86+
87+
foreach (var file in relevantFiles)
88+
{
89+
var fileHash = HashHelper.GetFileHash(file.FullName);
90+
completeManifest[file.Name] = fileHash;
91+
}
92+
93+
return Task.FromResult(completeManifest);
94+
}
7695
}

tests/UnturnedRedistUpdateTool.Tests/RedistUpdaterTests.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ public async Task ShouldCopyOnlyChangedFilesAndGenerateManifest()
2121

2222
File.WriteAllText(Path.Combine(source, "Unchanged.dll"), "same");
2323
File.WriteAllText(Path.Combine(target, "Unchanged.dll"), "same");
24+
25+
// Add a static file that should not be in manifest
26+
File.WriteAllText(Path.Combine(target, "README.md"), "static content");
2427

2528
var updater = new RedistUpdater(source, target, [], ["Test.dll"]);
2629
var (updated, manifests) = await updater.UpdateAsync();
@@ -38,6 +41,8 @@ public async Task ShouldCopyOnlyChangedFilesAndGenerateManifest()
3841

3942
var manifestContent = File.ReadAllText(manifestPath);
4043
manifestContent.ShouldContain("Test.dll");
44+
manifestContent.ShouldNotContain("Unchanged.dll"); // Not in updateFiles list
45+
manifestContent.ShouldNotContain("README.md"); // Static file
4146
}
4247

4348
[Fact]

0 commit comments

Comments
 (0)