Skip to content

Commit 6e334b6

Browse files
committed
Trash: Empty trash also deletes symlinks
1 parent 64a6c66 commit 6e334b6

2 files changed

Lines changed: 19 additions & 7 deletions

File tree

gitfourchette/trash.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def refreshFiles(self):
8989
def makeRoom(self, maxFiles: int):
9090
while len(self.trashFiles) > maxFiles:
9191
f = self.trashFiles.pop()
92-
if f.is_file():
92+
if self.pathIsTrashManaged(f):
9393
logger.debug(f"Deleting trash file {f}")
9494
f.unlink()
9595

test/test_trash.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,17 @@ def _fillTrashWithJunk(n):
1515
trash = Trash.instance()
1616
trash.refreshFiles()
1717
trash.clear()
18-
os.makedirs(trash.trashDir, exist_ok=True)
18+
trash.trashDir.mkdir(parents=True, exist_ok=True)
19+
1920
for i in range(n):
20-
with open(F"{trash.trashDir}/19991231T235900-test{i}.txt", "w") as junk:
21-
junk.write(F"test{i}")
21+
junkPath = Path(trash.trashDir, f"19991231T235900-test{i}.txt")
22+
23+
# Alternate between bogus text files and bogus symlinks
24+
if i % 2 == 0:
25+
junkPath.write_text(f"test{i}")
26+
else:
27+
junkPath.symlink_to(trash.trashDir)
28+
2229
trash.refreshFiles()
2330

2431

@@ -113,16 +120,21 @@ def testTrashFull(tempDir, mainWindow):
113120

114121

115122
def testClearTrash(mainWindow):
116-
assert Trash.instance().count() == 0
123+
trashInstance = Trash.instance()
124+
assert trashInstance.count() == 0
117125

118126
mainWindow.clearRescueFolder()
119127
acceptQMessageBox(mainWindow, "no discarded (patches|changes) to delete")
120128

121129
_fillTrashWithJunk(40)
122-
assert Trash.instance().count() == 40
130+
assert trashInstance.count() == 40
123131
mainWindow.clearRescueFolder()
124132
acceptQMessageBox(mainWindow, "delete.+40.+discarded (patches|changes)")
125-
assert Trash.instance().count() == 0
133+
assert trashInstance.count() == 0
134+
135+
trashInstance.refreshFiles()
136+
assert trashInstance.count() == 0
137+
assert not list(trashInstance.trashDir.iterdir())
126138

127139

128140
def testOpenTrashFolder(mainWindow):

0 commit comments

Comments
 (0)