Skip to content

Conversation

vbraun
Copy link
Member

@vbraun vbraun commented Sep 20, 2025

The destination of shutil.move must be the filename and not a directory to take advantage of move-overwrite filesystem semantic.

Fixes #40854

The destination of shutil.move must be the filename and not a
directory to take advantage of move-overwrite filesystem semantic.

Fixes sagemath#40854
Copy link

Documentation preview for this PR (built with commit ee36386; changes) is ready! 🎉
This preview will update shortly after each push to this PR.

@user202729
Copy link
Contributor

user202729 commented Sep 21, 2025

looking at the source code of shutil.move, the explanation is actually not true (os.rename is performed either way, just that an additional check is performed when the target is a directory), but as far as I can tell the net effect is the same.


def move(src, dst, copy_function=copy2):
    sys.audit("shutil.move", src, dst)
    real_dst = dst
    if os.path.isdir(dst):
		...
        # Using _basename instead of os.path.basename is important, as we must
        # ignore any trailing slash to avoid the basename returning ''
        real_dst = os.path.join(dst, _basename(src))

        if os.path.exists(real_dst):  # <<< the check here
            raise Error("Destination path '%s' already exists" % real_dst)
    try:
        os.rename(src, real_dst)
    except OSError:
		...
    return real_dst

@vbraun
Copy link
Member Author

vbraun commented Sep 21, 2025

I stand corrected...

vbraun pushed a commit to vbraun/sage that referenced this pull request Sep 22, 2025
sagemathgh-40857: Fix pdf docbuild failure if destination file exists
    
The destination of shutil.move must be the filename and not a directory
to take advantage of move-overwrite filesystem semantic.

Fixes sagemath#40854
    
URL: sagemath#40857
Reported by: Volker Braun
Reviewer(s):
vbraun pushed a commit to vbraun/sage that referenced this pull request Sep 24, 2025
sagemathgh-40857: Fix pdf docbuild failure if destination file exists
    
The destination of shutil.move must be the filename and not a directory
to take advantage of move-overwrite filesystem semantic.

Fixes sagemath#40854
    
URL: sagemath#40857
Reported by: Volker Braun
Reviewer(s):
vbraun pushed a commit to vbraun/sage that referenced this pull request Sep 27, 2025
sagemathgh-40857: Fix pdf docbuild failure if destination file exists
    
The destination of shutil.move must be the filename and not a directory
to take advantage of move-overwrite filesystem semantic.

Fixes sagemath#40854
    
URL: sagemath#40857
Reported by: Volker Braun
Reviewer(s):
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PDF documentation build fails with q
2 participants