Skip to content

Potential os.remove() Used on Directory Leading to Error in sync_folder Function #6

@RomongXrms

Description

@RomongXrms

In the sync_folder function, there is a section of code that handles the deletion of files and directories in the destination (dst) path that do not exist or are outdated in the source (src) path. The specific code snippet in question is:

if file.is_dir() and not file_in_src.exists():
    shutil.rmtree(file)
elif file.is_file() and (not file_in_src.exists() or file.stat().st_mtime < file_in_src.stat().st_mtime):
    os.remove(file)

The elif block potentially allows file_in_src to be a directory, but os.remove cannot delete directories (which causes Python to throw an exception).
To reproduce this issue, you can change the .gitkeep file in the Cards directory to a directory.
I'm not sure if this qualifies as a problem. For simple project builds, it is rare for a file to mutate into a directory or for a file to change without its modification time being updated.
I really like your incremental update build approach, which offers better performance for large project builds.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions