Skip to content

Commit d1a5c7f

Browse files
committed
Better compliance to spec
1 parent a94a32b commit d1a5c7f

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

source/trashcan.d

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,6 @@ private:
8484
assert(numberedBaseName("/root/file", 2) == "file 2");
8585
}
8686

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\nline\top".escapeValue() == `a\\next\nline\top`);
94-
}
95-
9687
@trusted string ensureDirExists(string dir) {
9788
std.file.mkdirRecurse(dir);
9889
return dir;
@@ -280,10 +271,12 @@ private:
280271
dataPath = dataPath.absolutePath;
281272

282273
string trashBasePath;
274+
bool usingTopdir = false;
275+
string fileTopDir;
283276

284277
if ((options & TrashOptions.useTopDirs) != 0) {
285278
string dataTopDir = topDir(dataPath);
286-
string fileTopDir = topDir(path);
279+
fileTopDir = topDir(path);
287280

288281
enforce(fileTopDir.length, "Could not get topdir of file being trashed");
289282
enforce(dataTopDir.length, "Could not get topdir of home data directory");
@@ -292,10 +285,12 @@ private:
292285
try {
293286
string diskTrash = checkDiskTrash(fileTopDir, (options & TrashOptions.checkStickyBit) != 0);
294287
trashBasePath = ensureUserTrashSubdir(diskTrash);
288+
usingTopdir = true;
295289
} catch(Exception e) {
296290
try {
297291
if ((options & TrashOptions.fallbackToUserDir) != 0) {
298292
trashBasePath = ensureUserTrashDir(fileTopDir);
293+
usingTopdir = true;
299294
} else {
300295
throw e;
301296
}
@@ -321,12 +316,13 @@ private:
321316

322317
import std.datetime;
323318
import std.conv : octal;
319+
import std.uri;
324320
import core.stdc.errno;
325321

326322
auto currentTime = Clock.currTime;
327323
currentTime.fracSecs = Duration.zero;
328324
string timeString = currentTime.toISOExtString();
329-
string contents = format("[Trash Info]\nPath=%s\nDeletionDate=%s\n", path.escapeValue(), timeString);
325+
string contents = format("[Trash Info]\nPath=%s\nDeletionDate=%s\n", (usingTopdir ? path.relativePath(fileTopDir) : path).encode(), timeString);
330326

331327
const mode = O_CREAT | O_WRONLY | O_EXCL;
332328
int fd;

0 commit comments

Comments
 (0)