Skip to content

fix: FileSystem::remove_recursive() removes the directory itself too - #3529

Merged
ice0 merged 1 commit into
synfig:masterfrom
rodolforg:fix-file-remove-recursive
Mar 23, 2025
Merged

ice0 merged 1 commit into
synfig:masterfrom
rodolforg:fix-file-remove-recursive

Conversation

@rodolforg

Copy link
Copy Markdown
Contributor

Before this commit, FileSystem::remove_recursive() removes:

  • a single file, if the path points to one
  • all directory contents, if the path points to a directory

After this commit, the path itself will be removed if it is a directory (and its subdirs, of course).

Currently, this method is only used in three places as shown by the following git grep output:

synfig-core/src/modules/mod_ffmpeg/trgt_ffmpeg.cpp:             if (!FileSystemNative::instance()->remove_recursive(sound_filename)) {
synfig-core/src/synfig/filesystem.cpp:bool FileSystem::remove_recursive(const filesystem::Path& filename)
synfig-core/src/synfig/filesystem.cpp:                  if (!remove_recursive(filename / i))
synfig-core/src/synfig/filesystem.h:            bool remove_recursive(const filesystem::Path& filename);
synfig-studio/src/gui/app.cpp:  FileSystemNative::instance()->remove_recursive(tmp_filename);
synfig-studio/src/synfigapp/instance.cpp:                       //new_canvas_filesystem->remove_recursive(CanvasFileNaming::container_prefix);
synfig-studio/src/synfigapp/instance.cpp:       //new_canvas_filesystem->remove_recursive(CanvasFileNaming::container_prefix);
  • In Target FFmpeg, it is used to delete a single (temporary) audio file while exporting the animation;
  • In FileSystem itself, because it is a recursive method
  • In studio::App::open_from_plugin(), to remove a temp file that a plugin changes

Therefore, all current cases call this method to remove a single file only, and that is the reason the issue was not detected.

@github-actions

Copy link
Copy Markdown

Thank you for contributing!
Below is how your contribution will appear in Synfig's release notes. Review it and improve your pull request's title and description so that your contribution is clear. You can add images, videos, and anything else you want. Have fun!

🐞 Bug Fixes

  • FileSystem::remove_recursive() removes the directory itself too

    Before this commit, FileSystem::remove_recursive() removes:

    • a single file, if the path points to one
    • all directory contents, if the path points to a directory

    After this commit, the path itself will be removed if it is a directory (and its subdirs, of course).

    Currently, this method is only used in three places as shown by the following git grep output:

    synfig-core/src/modules/mod_ffmpeg/trgt_ffmpeg.cpp:             if (!FileSystemNative::instance()->remove_recursive(sound_filename)) {  
    synfig-core/src/synfig/filesystem.cpp:bool FileSystem::remove_recursive(const filesystem::Path& filename)  
    synfig-core/src/synfig/filesystem.cpp:                  if (!remove_recursive(filename / i))  
    synfig-core/src/synfig/filesystem.h:            bool remove_recursive(const filesystem::Path& filename);  
    synfig-studio/src/gui/app.cpp:  FileSystemNative::instance()->remove_recursive(tmp_filename);  
    synfig-studio/src/synfigapp/instance.cpp:                       //new_canvas_filesystem->remove_recursive(CanvasFileNaming::container_prefix);  
    synfig-studio/src/synfigapp/instance.cpp:       //new_canvas_filesystem->remove_recursive(CanvasFileNaming::container_prefix);  
    
    • In Target FFmpeg, it is used to delete a single (temporary) audio file while exporting the animation;
    • In FileSystem itself, because it is a recursive method
    • In studio::App::open_from_plugin(), to remove a temp file that a plugin changes

    Therefore, all current cases call this method to remove a single file only, and that is the reason the issue was not detected.

@ice0
ice0 merged commit ab844d6 into synfig:master Mar 23, 2025
@ice0

ice0 commented Mar 23, 2025

Copy link
Copy Markdown
Collaborator

Merged. Thank you!

@rodolforg
rodolforg deleted the fix-file-remove-recursive branch March 23, 2025 08:52
Stargazer10101 pushed a commit to Stargazer10101/synfig that referenced this pull request Apr 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants