Giter Club home page Giter Club logo

Comments (11)

baudehlo avatar baudehlo commented on August 26, 2024

Interesting - what's your use case for this? I would think using it leaves you open to race conditions.

from node-fs-ext.

lobodpav avatar lobodpav commented on August 26, 2024

It leaves you if you use it incorrectly, that is correct.
The use case is that in my app, I perform a startup check of availability of essential services and also checking if the log directory (say /var/log/myApp/) is writable to ensure log files can be created and rotated. If the dir is not writable, I prevent the app to start.

from node-fs-ext.

baudehlo avatar baudehlo commented on August 26, 2024

But wouldn't attempting to open the log file for writing achieve the same thing?

from node-fs-ext.

lobodpav avatar lobodpav commented on August 26, 2024

Nope. The log dir might have read-only permissions while the log file will have write. You start the app, open the log file for writing and it works just fine.
However, once you need to rotate the logs, you will fail.

from node-fs-ext.

baudehlo avatar baudehlo commented on August 26, 2024

Ah interesting!

I wonder if we can find a Windows API equivalent.

from node-fs-ext.

lobodpav avatar lobodpav commented on August 26, 2024

There must be something. But I have never developed in Windows so neither a clue what API there is nor how Windows node addons are built :(

from node-fs-ext.

baudehlo avatar baudehlo commented on August 26, 2024

Me either. The way I did it for fs-ext current functions was to look at other languages' implementations of those functions.

from node-fs-ext.

lobodpav avatar lobodpav commented on August 26, 2024

I see. Maybe some googling would help. Will try it out if I find a bit of time :)

from node-fs-ext.

baudehlo avatar baudehlo commented on August 26, 2024

From some googling, I think it'll compile natively on Windows due to the POSIX layer. Perl's POSIX.xs code has no ifdef code for Win32 around the access() function.

But the FreeBSD man page warns that access() should never be used due to race conditions, so I'd rather not add it to fs-ext (because part of the purpose of writing fs-ext was to mitigate huge security holes in Node code due to lack of file locking), so I'm going to close this issue.

from node-fs-ext.

 avatar commented on August 26, 2024

Venturing off-topic, but: As a workaround for the log rotation scenario, you might be able to use some combination of fs.stat() and process.getuid() (or, possibly better, process.geteuid() from node-posix) to simulate the access() check and determine whether or not the log directory is likely to be writable. Another possibility might be to just try to create a file in the target directory at startup, see if it errors out, and then unlink it if the creation was successful.

from node-fs-ext.

lobodpav avatar lobodpav commented on August 26, 2024

Well, I have implemented the access() wrapper myself so that I do use my own unix-access module at the time being and it serves its purpose. By this issue I wanted to make it part of fs-ext not to have FS functions crumbled into many modules.

from node-fs-ext.

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.