Giter VIP home page Giter VIP logo

Comments (7)

othiym23 avatar othiym23 commented on August 20, 2024

Optimally it'd clean up any temp files on exit.

Optimally, yes, but cleanup on exit in Node is not really very optimal (because you have no guarantees that anything async will complete before the process shuts down). We could enqueue files into a list and then fs.unlinkSync() them on exit (npm 2 does something similar for rollback), but that feels a little high-level for what is right now a package focused on doing one relatively simple thing.

Also, are there any reasons to not write the temp files to os.tmpdir()?

VERY YES. The atomicity of the operation depends on fs.rename() being atomic, and you can't rename across filesystem boundaries (since all you're doing is changing what name is mapped to a given inode).

from fs-write-stream-atomic.

kevva avatar kevva commented on August 20, 2024

I guess we could do it manually in our package by removing this.__atomicTmp on process.exit or process.SIGINT.

from fs-write-stream-atomic.

othiym23 avatar othiym23 commented on August 20, 2024

It's tricky, because I've seen exit handlers fail to fire once there are more than a couple process.on('exit') listeners in some versions of Node.

from fs-write-stream-atomic.

sindresorhus avatar sindresorhus commented on August 20, 2024

because you have no guarantees that anything async will complete before the process shuts down

Maybe someday (hopefully I'm still alive :p): http://nodejs.org/docs/v0.11.13/api/process.html#process_event_beforeexit

It's tricky, because I've seen exit handlers fail to fire once there are more than a couple process.on('exit') listeners in some versions of Node.

Still better than nothing though.

from fs-write-stream-atomic.

othiym23 avatar othiym23 commented on August 20, 2024

Yeah, beforeExit is a possibility, but it'd still be best-effort, because fs.writeStreamAtomic's primary consumer (not naming any names cough) is still going to need to support 0.10 after the release of 0.12, and realistically, people will complain if it doesn't work with 0.8 for some time after 0.12's release as well. That said, if somebody put together a patch adding this in an opt-in, backwards-compatible way, we'd take it.

from fs-write-stream-atomic.

edef1c avatar edef1c commented on August 20, 2024

Failing to remove temporary files isn't a disaster, it's merely the current behaviour.
Adding best-effort tempfile removal shouldn't be blocked by imperfection, imo.

from fs-write-stream-atomic.

sholladay avatar sholladay commented on August 20, 2024

It has been about a year, with a few major versions of Node with beforeExit. Any updated thoughts on this?

from fs-write-stream-atomic.

Related Issues (6)

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.