Page MenuHome

VSE: Remove empty disk cache directories
Needs RevisionPublic

Authored by Richard Antalik (ISS) on May 10 2021, 6:58 PM.

Details

Summary

When disk cache files were removed, directories stayed in place.

Remove directories when all files are removed from them.


This is probably best solution I can come up with. I don't quite like, that directories have to be traversed towards higher level, because if somehow condition STREQ(path, seq_disk_cache_base_dir() fails and BLI_dir_is_empty(path) fails as well, this can result in rm -rf /.
Alternative would be to track status during initial cache traversing and storing empty branches, that can be removed at once. Which would help when directory is not removed for some reason even when no cache files aren't present.

Diff Detail

Repository
rB Blender
Branch
dcache-cleanpath (branched from master)
Build Status
Buildable 14476
Build 14476: arc lint + arc unit

Event Timeline

Richard Antalik (ISS) requested review of this revision.May 10 2021, 6:58 PM
Richard Antalik (ISS) created this revision.
Sergey Sharybin (sergey) requested changes to this revision.May 11 2021, 9:39 AM

How about taking an advantage of the fact that rmdir() will return -1 and errno will be set to ENOTEMPTY when rmdir() is used on a non-empty directory? This way you don't need to have BLI_dir_is_empty(). So you can simply do BLI_delete(dir, true, false);.

The iterative nature of the logic is hard to follow for me. Is it possible to rephrase it more explicitly, something like this (a pseudo code, kinda mix of C and Python's pathlib):

BLI_delete(Path(base_path) / "subfolder" / "cache_version", false, false);
BLI_delete(base_path, true, false);
This revision now requires changes to proceed.May 11 2021, 9:39 AM