From 1816634e6f494b4fcbde693bdeed06a5d1875dc3 Mon Sep 17 00:00:00 2001 From: Jan Jurzitza Date: Thu, 30 Nov 2017 10:55:23 +0100 Subject: [PATCH 1/2] added removeDirectory and getDirectorySize --- core/vibe/core/file.d | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/core/vibe/core/file.d b/core/vibe/core/file.d index 9ab6dbe769..c034c12204 100644 --- a/core/vibe/core/file.d +++ b/core/vibe/core/file.d @@ -233,6 +233,19 @@ void removeFile(string path) std.file.remove(path); } +/** + Removes a directory including its files recursively +*/ +void removeDirectory(Path path) +{ + removeDirectory(path.toNativeString()); +} +/// ditto +void removeDirectory(string path) +{ + std.file.rmdirRecurse(path); +} + /** Checks if a file exists */ @@ -261,6 +274,24 @@ FileInfo getFileInfo(string path) return getFileInfo(Path(path)); } +/** + Sums up all file sizes recursively in a directory + + Throws: A `FileException` is thrown if the file does not exist. +*/ +size_t getDirectorySize(Path path) +{ + return getDirectorySize(path.toNativeString()); +} +/// ditto +size_t getDirectorySize(string path) +{ + size_t total; + foreach( DirEntry ent; dirEntries(path, SpanMode.depth) ) + total += makeFileInfo(ent).size; + return total; +} + /** Creates a new directory. */ From 3190f0ab894a5ff779270f4f037696627d0c234c Mon Sep 17 00:00:00 2001 From: Jan Jurzitza Date: Mon, 4 Dec 2017 13:11:55 +0100 Subject: [PATCH 2/2] made removeDirectory & getDirectorySize trusted --- core/vibe/core/file.d | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/vibe/core/file.d b/core/vibe/core/file.d index c034c12204..b3c0cfc6b3 100644 --- a/core/vibe/core/file.d +++ b/core/vibe/core/file.d @@ -242,7 +242,7 @@ void removeDirectory(Path path) } /// ditto void removeDirectory(string path) -{ +@trusted { std.file.rmdirRecurse(path); } @@ -285,7 +285,7 @@ size_t getDirectorySize(Path path) } /// ditto size_t getDirectorySize(string path) -{ +@trusted { size_t total; foreach( DirEntry ent; dirEntries(path, SpanMode.depth) ) total += makeFileInfo(ent).size;