@@ -84,15 +84,6 @@ private:
84
84
assert (numberedBaseName(" /root/file" , 2 ) == " file 2" );
85
85
}
86
86
87
- @trusted string escapeValue(string value) pure {
88
- return value.replace(" \\ " , ` \\` ).replace(" \n " , ` \n` ).replace(" \r " , ` \r` ).replace(" \t " , ` \t` );
89
- }
90
-
91
- unittest
92
- {
93
- assert (" a\\ next\n line\t op" .escapeValue() == ` a\\next\nline\top` );
94
- }
95
-
96
87
@trusted string ensureDirExists(string dir) {
97
88
std.file.mkdirRecurse (dir);
98
89
return dir;
@@ -280,10 +271,12 @@ private:
280
271
dataPath = dataPath.absolutePath;
281
272
282
273
string trashBasePath;
274
+ bool usingTopdir = false ;
275
+ string fileTopDir;
283
276
284
277
if ((options & TrashOptions.useTopDirs) != 0 ) {
285
278
string dataTopDir = topDir(dataPath);
286
- string fileTopDir = topDir(path);
279
+ fileTopDir = topDir(path);
287
280
288
281
enforce(fileTopDir.length, " Could not get topdir of file being trashed" );
289
282
enforce(dataTopDir.length, " Could not get topdir of home data directory" );
@@ -292,10 +285,12 @@ private:
292
285
try {
293
286
string diskTrash = checkDiskTrash(fileTopDir, (options & TrashOptions.checkStickyBit) != 0 );
294
287
trashBasePath = ensureUserTrashSubdir(diskTrash);
288
+ usingTopdir = true ;
295
289
} catch (Exception e) {
296
290
try {
297
291
if ((options & TrashOptions.fallbackToUserDir) != 0 ) {
298
292
trashBasePath = ensureUserTrashDir(fileTopDir);
293
+ usingTopdir = true ;
299
294
} else {
300
295
throw e;
301
296
}
@@ -321,12 +316,13 @@ private:
321
316
322
317
import std.datetime ;
323
318
import std.conv : octal;
319
+ import std.uri ;
324
320
import core.stdc.errno ;
325
321
326
322
auto currentTime = Clock .currTime;
327
323
currentTime.fracSecs = Duration.zero;
328
324
string timeString = currentTime.toISOExtString();
329
- string contents = format(" [Trash Info]\n Path=%s\n DeletionDate=%s\n " , path.escapeValue (), timeString);
325
+ string contents = format(" [Trash Info]\n Path=%s\n DeletionDate=%s\n " , (usingTopdir ? path.relativePath(fileTopDir) : path).encode (), timeString);
330
326
331
327
const mode = O_CREAT | O_WRONLY | O_EXCL ;
332
328
int fd;
0 commit comments