Coder Social home page Coder Social logo

Comments (8)

lrhn avatar lrhn commented on July 28, 2024 3

Checking first is a race condition. The only way to be certain is to have the operation fail if it is not the first to create the target file.
That will allow separate processes to all create files in the same directory, as long as they all retry with a fresh name on failure, using the file system itself as the mutex.

That does mean that the operation itself must fail atomically, not just move a non-atomic extra check into the same library function. That buys nothing.

If there is no atomic "own this file name from scratch" operation in the OS, then it's probably not going to be possible.

from sdk.

lrhn avatar lrhn commented on July 28, 2024 1

Changing the signature of an interface method breaks existing third-party classes which implement that interface, because they no longer satisfy the interface signature of that method

from sdk.

a-siva avatar a-siva commented on July 28, 2024 1

@a-siva if rename takes an optional parameter to avoid the overwrite, how this is creating a breaking change? if you not changing the default behavior I think there is no breaking change. Do you want to modify rename differently?

See comment above .

from sdk.

mraleph avatar mraleph commented on July 28, 2024

If you are concerned about newPath existing you can just check that before executing rename. Is there any reason why you want this behavior to be baked into rename itself?

cc @brianquinlan @lrhn

from sdk.

mraleph avatar mraleph commented on July 28, 2024

Good point about atomicity.

  • Linux has renameat2 with RENAME_NOREPLACE (Linux 3.15, glibc 2.28)
  • Mac OS X has renameatx_np with RENAME_EXCL (10.12+)
  • On Windows MoveFileExW without MOVEFILE_REPLACE_EXISTING should also error

Both Linux and Mac OS X require underlying file system to support atomic replacement (not all file systems do).

from sdk.

stephane-archer avatar stephane-archer commented on July 28, 2024

@mraleph can the requirement of the underlying file system be an issue?
Can it be detected and an exception be thrown in that case?

from sdk.

a-siva avatar a-siva commented on July 28, 2024

This is going to be a breaking change and would require updates in a number of packages that override File operations.

from sdk.

stephane-archer avatar stephane-archer commented on July 28, 2024

@a-siva if rename takes an optional parameter to avoid the overwrite, how this is creating a breaking change?
if you not changing the default behavior I think there is no breaking change.
Do you want to modify rename differently?

from sdk.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.