Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Montagne <montagne29@wanadoo.fr>2014-06-23 15:42:19 +0400
committerBastien Montagne <montagne29@wanadoo.fr>2014-06-23 15:42:54 +0400
commit414c70435dcd52eb67df59f56132837de0a63b64 (patch)
tree27f305e446db2c647e8725dfbc47e6468b880701 /source/blender/blenlib/intern/fileops.c
parent9b987103f6684f9abe55cd536b718bc95cb06f24 (diff)
T39690: Modifications to Blender's 'temp dir' system.
Current temporary data of Blender suffers one major issue - default 'temp' dir on Windows is never automatically cleaned up, and can end being quite big when used by Blender, especially when we have to store per-process data (using getpid() in file names). To address this, this patch: * Divides tempdir paths in two, one for 'base' temp dir (the same as previous unique tempdir path), the other is a mkdtemp-generated sub-dir, specific to each Blender instance. * Only uses base tempdir when we need some shallow persistance accross Blender sessions - and we always reuse the same filename (quit.blend...) or generate small file (crash reports...). * Uses temp sub-dir for heavy files like pointcache or renderEXRs (Save Buffer option). * Erases temp sub-dir on quit or crash. To get this working it also adds a working 'recursive delete' to BLI_delete() under Windows. Note that, as in current code, the 'recover render result' hack-feature that was possible with SaveBuffer option is still removed. A real renderresult cache feature will be added soon, though. Reviewers: campbellbarton, brecht, sergey Reviewed By: campbellbarton, sergey CC: sergey Differential Revision: https://developer.blender.org/D531
Diffstat (limited to 'source/blender/blenlib/intern/fileops.c')
-rw-r--r--source/blender/blenlib/intern/fileops.c71
1 files changed, 59 insertions, 12 deletions
diff --git a/source/blender/blenlib/intern/fileops.c b/source/blender/blenlib/intern/fileops.c
index 5df46752e3b..c1a103b641e 100644
--- a/source/blender/blenlib/intern/fileops.c
+++ b/source/blender/blenlib/intern/fileops.c
@@ -48,6 +48,7 @@
# include <io.h>
# include "BLI_winstuff.h"
# include "BLI_callbacks.h"
+# include "BLI_fileops_types.h"
# include "utf_winfunc.h"
# include "utfconv.h"
#else
@@ -284,26 +285,72 @@ int BLI_access(const char *filename, int mode)
return uaccess(filename, mode);
}
-int BLI_delete(const char *file, bool dir, bool recursive)
+static bool delete_unique(const char *path, const bool dir)
{
- int err;
-
- UTF16_ENCODE(file);
+ bool err;
- if (recursive) {
- callLocalErrorCallBack("Recursive delete is unsupported on Windows");
- err = 1;
- }
- else if (dir) {
- err = !RemoveDirectoryW(file_16);
+ UTF16_ENCODE(path);
+
+ if (dir) {
+ err = !RemoveDirectoryW(path_16);
if (err) printf("Unable to remove directory");
}
else {
- err = !DeleteFileW(file_16);
+ err = !DeleteFileW(path_16);
if (err) callLocalErrorCallBack("Unable to delete file");
}
- UTF16_UN_ENCODE(file);
+ UTF16_UN_ENCODE(path);
+
+ return err;
+}
+
+static bool delete_recursive(const char *dir)
+{
+ struct direntry *filelist, *fl;
+ bool err = false;
+ unsigned int nbr, i;
+
+ i = nbr = BLI_dir_contents(dir, &filelist);
+ fl = filelist;
+ while(i--) {
+ char file[8];
+ BLI_split_file_part(fl->path, file, sizeof(file));
+ if (STREQ(file, ".") || STREQ(file, "..")) {
+ /* Skip! */
+ }
+ else if (S_ISDIR(fl->type)) {
+ if (delete_recursive(fl->path) {
+ err = true;
+ }
+ }
+ else {
+ if (delete_unique(fl->path, false)) {
+ err = true;
+ }
+ }
+ ++fl;
+ }
+
+ if (!err && delete_unique(dir, true)) {
+ err = true;
+ }
+
+ BLI_free_filelist(filelist, nbr);
+
+ return err;
+}
+
+int BLI_delete(const char *file, bool dir, bool recursive)
+{
+ int err;
+
+ if (recursive) {
+ err = delete_recursive(file);
+ }
+ else {
+ err = delete_unique(file, dir);
+ }
return err;
}