Comments (11)
Interesting - what's your use case for this? I would think using it leaves you open to race conditions.
from node-fs-ext.
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.
But wouldn't attempting to open the log file for writing achieve the same thing?
from node-fs-ext.
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.
Ah interesting!
I wonder if we can find a Windows API equivalent.
from node-fs-ext.
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.
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.
I see. Maybe some googling would help. Will try it out if I find a bit of time :)
from node-fs-ext.
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.
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.
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)
- Fcntl not working on Windows 10 HOT 1
- Can't install it anymore - Is this deprecated ? HOT 4
- Compiled against a different Node.js version using NODE_MODULE_VERSION xx HOT 1
- Does this check whether the file is occupied
- Won't compile with "No receipt for 'com.apple.pkg.CLTools_Executables' found at '/'."
- Abandoned? HOT 2
- fs-ext doesn't install on Windows HOT 1
- Error installing fs-ext 1.1.0 HOT 10
- node@11 freezing constants HOT 1
- Hangs forever on multiple simultaneous calls HOT 12
- Node-fs-ext and Windows 10 HOT 2
- F_WRLCK not added to constants in Node.js 11 HOT 2
- Install fails on OpenBSD
- Compatible with nodejs 11? HOT 3
- Don't override fs module HOT 2
- node_modules/fs-ext/build/Release constantly disappears in yarn HOT 2
- EBADF, Bad file descriptor
- flock not working with fs.open ?! HOT 2
- This seems to break for worker threads HOT 1
- [feature request] BigInt Support
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-fs-ext.