Skip to content

Commit

Permalink
fix: delete hard link test files even on errors
Browse files Browse the repository at this point in the history
  • Loading branch information
anna-is-cute committed Sep 8, 2024
1 parent c5a294f commit cb5687c
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions DownloadTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -322,22 +322,34 @@ private void CreateDirectories() {
}

private async Task TestHardLinks() {
string? a = null;
string? b = null;

try {
var a = Path.Join(this.PenumbraModPath, Path.GetRandomFileName());
a = Path.Join(this.PenumbraModPath, Path.GetRandomFileName());
await FileHelper.Create(a, true).DisposeAsync();

var b = Path.Join(this.PenumbraModPath, Path.GetRandomFileName());
b = Path.Join(this.PenumbraModPath, Path.GetRandomFileName());
FileHelper.CreateHardLink(a, b);
this.SupportsHardLinks = true;

try {
File.Delete(a);
File.Delete(b);
} catch (Exception ex) {
Plugin.Log.Warning(ex, "Could not delete temp files");
}
} catch (InvalidOperationException) {
this.SupportsHardLinks = false;
} finally {
if (a != null) {
try {
File.Delete(a);
} catch (Exception ex) {
Plugin.Log.Warning(ex, "Could not delete temp files");
}
}

if (b != null) {
try {
File.Delete(b);
} catch (Exception ex) {
Plugin.Log.Warning(ex, "Could not delete temp files");
}
}
}
}

Expand Down

0 comments on commit cb5687c

Please sign in to comment.