-
Notifications
You must be signed in to change notification settings - Fork 0
Fix incomplete plugin directory deletion on uninstall #5
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
Changes from all commits
f87b115
0de552f
f3f9d62
7b3216b
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 |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| using Flow.Launcher.Plugin.SharedCommands; | ||
| using NUnit.Framework; | ||
| using NUnit.Framework.Legacy; | ||
| using System.IO; | ||
|
|
||
| namespace Flow.Launcher.Test | ||
| { | ||
|
|
@@ -50,5 +51,89 @@ public void GivenTwoPathsAreTheSame_WhenCheckPathContains_ThenShouldBeExpectedRe | |
| { | ||
| ClassicAssert.AreEqual(expectedResult, FilesFolders.PathContains(parentPath, path, allowEqual: expectedResult)); | ||
| } | ||
|
|
||
| [Test] | ||
| public void TryDeleteDirectoryRobust_WhenDirectoryDoesNotExist_ReturnsTrue() | ||
| { | ||
| // Arrange | ||
| string nonExistentPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); | ||
|
|
||
| // Act | ||
| bool result = FilesFolders.TryDeleteDirectoryRobust(nonExistentPath); | ||
|
|
||
| // Assert | ||
| ClassicAssert.IsTrue(result); | ||
| } | ||
|
|
||
| [Test] | ||
| public void TryDeleteDirectoryRobust_WhenDirectoryIsEmpty_DeletesSuccessfully() | ||
| { | ||
| // Arrange | ||
| string tempDir = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); | ||
| Directory.CreateDirectory(tempDir); | ||
|
|
||
| // Act | ||
| bool result = FilesFolders.TryDeleteDirectoryRobust(tempDir); | ||
|
|
||
| // Assert | ||
| ClassicAssert.IsTrue(result); | ||
| ClassicAssert.IsFalse(Directory.Exists(tempDir)); | ||
| } | ||
|
|
||
| [Test] | ||
| public void TryDeleteDirectoryRobust_WhenDirectoryHasFiles_DeletesSuccessfully() | ||
| { | ||
| // Arrange | ||
| string tempDir = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); | ||
| Directory.CreateDirectory(tempDir); | ||
| File.WriteAllText(Path.Combine(tempDir, "test.txt"), "test content"); | ||
|
|
||
| // Act | ||
| bool result = FilesFolders.TryDeleteDirectoryRobust(tempDir); | ||
|
|
||
| // Assert | ||
| ClassicAssert.IsTrue(result); | ||
| ClassicAssert.IsFalse(Directory.Exists(tempDir)); | ||
| } | ||
|
|
||
| [Test] | ||
| public void TryDeleteDirectoryRobust_WhenDirectoryHasNestedStructure_DeletesSuccessfully() | ||
| { | ||
| // Arrange | ||
| string tempDir = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); | ||
| Directory.CreateDirectory(tempDir); | ||
| string subDir1 = Path.Combine(tempDir, "SubDir1"); | ||
| string subDir2 = Path.Combine(tempDir, "SubDir2"); | ||
| Directory.CreateDirectory(subDir1); | ||
| Directory.CreateDirectory(subDir2); | ||
| File.WriteAllText(Path.Combine(subDir1, "file1.txt"), "content1"); | ||
| File.WriteAllText(Path.Combine(subDir2, "file2.txt"), "content2"); | ||
| File.WriteAllText(Path.Combine(tempDir, "root.txt"), "root content"); | ||
|
|
||
| // Act | ||
| bool result = FilesFolders.TryDeleteDirectoryRobust(tempDir); | ||
|
|
||
| // Assert | ||
| ClassicAssert.IsTrue(result); | ||
| ClassicAssert.IsFalse(Directory.Exists(tempDir)); | ||
| } | ||
|
|
||
| [Test] | ||
| public void TryDeleteDirectoryRobust_WhenFileIsReadOnly_RemovesAttributeAndDeletes() | ||
| { | ||
| // Arrange | ||
| string tempDir = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); | ||
| Directory.CreateDirectory(tempDir); | ||
| string filePath = Path.Combine(tempDir, "readonly.txt"); | ||
| File.WriteAllText(filePath, "readonly content"); | ||
| File.SetAttributes(filePath, FileAttributes.ReadOnly); | ||
|
|
||
| // Act | ||
| bool result = FilesFolders.TryDeleteDirectoryRobust(tempDir); | ||
|
|
||
| // Assert | ||
| ClassicAssert.IsTrue(result); | ||
| ClassicAssert.IsFalse(Directory.Exists(tempDir)); | ||
| } | ||
|
Comment on lines
+55
to
+137
|
||
| } | ||
| } | ||
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.
Off-by-one error in retry logic. The loop condition 'attempt <= maxRetries' with 'attempt' starting at 0 means that when maxRetries is 3, the code will make 4 attempts (0, 1, 2, 3) instead of the intended 3. Change the loop condition to 'attempt < maxRetries' to ensure the number of attempts matches the parameter value, or adjust the documentation to clarify that maxRetries represents the number of retries after the initial attempt.