BLI_fileops: Harmonize 'rename' behaviors accross platforms. #115096
No reviewers
Labels
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
4 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#115096
Loading…
Reference in New Issue
No description provided.
Delete Branch "mont29/blender:tmp-file-rename"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This commit aim at making the behaviors of
BLI_rename
andBLI_rename_overwrite
more consistent and coherent across allsupported platforms.
BLI_rename
now only succeeds in case the targetto
path does notexists (similar to Windows
rename
behavior).BLI_rename_overwrite
allows to replace an existing targetto
fileor (empty) directory (similar to Unix
rename
behavior).NOTE: In case the target is open by some process on the system, trying
to overwrite it will still fail on Windows, while it should succeed on
Unix-like systems.
The main change for Windows is the usage of
MoveFileExW
instead of
_wrename
, which allows for 'native support' of fileoverwrite (using the
MOVEFILE_REPLACE_EXISTING
flag). Directoriesstill need to be explicitly removed though.
The main change for *nix systems is the use of
renamex_np
(OSX) orrenameat2
(most Linux systems) to allow forbidding renaming to analready existing target in an 'atomic' way.
NOTE: While this commit aims at avoiding the TOC/TOU problem as
much as possible by using available system's primitives for most
common cases, there are some situations where race conditions
(filesystem changes between checks on FS state, and actual rename
operation) remain possible.
@blender-bot build
Note that since this is (mostly) changing things on Windows, and unittests can only do so much,, would be nice to also have some more experienced Windows devs to check on it. @LazyDodo maybe?
@ -449,3 +440,4 @@
return 1;
}
if (BLI_exists(to)) {
Did you look into having non-overwrite behavior which does not suffer from TOC-TOU?
Done, although we cannot fully eliminate the TOC/TOU case, in particular for BSD OSs.
@blender-bot build
@blender-bot build
@ -467,0 +482,4 @@
}
return rename(from, to);
#else /* __linux__ */
return renameat2(AT_FDCWD, from, AT_FDCWD, to, RENAME_NOREPLACE);
There are also Linuxes without glibc, and other Unixes that don't support this. I think we should check if
renameat2
is supported, maybe like this:@blender-bot build
@ -467,0 +481,4 @@
return renameat2(AT_FDCWD, from, AT_FDCWD, to, RENAME_NOREPLACE);
#else
/* At least all BSD's currently. */
if (!BLI_exists(to)) {
Shouldn't this be
if (BLI_exists(to)) {
?From me reading the code seems fine.
Works fine on macOS.
Hi @mont29,
This commit breaks build for me on FreeBSD using clang 15.
I get
error: function-like macro '__GLIBC_PREREQ' is not defined
While it seems reasonable having
defined(__GLIBC_PREREQ) && __GLIBC_PREREQ(2, 28)
in the same#if
it doesn't seem to work with clang.Breaking it into two lines does work for me.
@ShaneAmbler Hi, thanks for the report, suggested fix seems reasonable! Do you want to submit a PR for it (then you can be officially listed as contributor), or should I go on and commit the change?
I'm fine with you just adjusting it
@ShaneAmbler committed as
1592aaf01a
, thanks!