Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Semver-major changes #173

Open
wants to merge 34 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
ea9e6bc
Create/use global shared retry queue.
coreyfarrell Aug 5, 2019
43ba0b1
Add test flag allowing reset of fs.close / fs.closeSync
coreyfarrell Aug 8, 2019
a91bd18
Remove changes not needed in v4.x
coreyfarrell Aug 8, 2019
3cf751e
Require Node.js 8, update devDependencies
coreyfarrell Aug 5, 2019
99b67e5
Drop legacy-streams.js
coreyfarrell Aug 5, 2019
91ed07a
Remove v0.6.2 backport fix for fs.lchmod
coreyfarrell Aug 5, 2019
cb8ca43
Remove fs.*stat* gid/uid fixup
coreyfarrell Aug 5, 2019
d70ba36
Drop fallback for util.debuglog
coreyfarrell Aug 6, 2019
7e52d7f
Unify ENFILE/EMFILE error checks
coreyfarrell Aug 6, 2019
be2498f
Create unified ReadStream / WriteStream patching function
coreyfarrell Aug 6, 2019
2bb23c3
Modernize / simplify clone.js
coreyfarrell Aug 6, 2019
82736a8
Modernize graceful-fs.js
coreyfarrell Aug 6, 2019
5af296f
Modernize win32 fs.rename polyfill
coreyfarrell Aug 7, 2019
99851ef
Modernize fs.read / fs.readSync polyfills
coreyfarrell Aug 7, 2019
da0b918
Unify chown/chmod polyfills
coreyfarrell Aug 7, 2019
8e34dfc
Remove TEST_GRACEFUL_FS_GLOBAL_PATCH, test with gfs.gracefulify
coreyfarrell Aug 7, 2019
67dfc90
Split win32 fs.rename patcher to separate source file
coreyfarrell Aug 7, 2019
b28befc
Create noop.js
coreyfarrell Aug 7, 2019
c0da35c
Move lutimes polyfills to separate file
coreyfarrell Aug 7, 2019
01fdd0b
Collect code coverage
coreyfarrell Aug 8, 2019
6d8dae1
Full coverage
coreyfarrell Aug 8, 2019
8853947
Modernize tests, make style consistent
coreyfarrell Aug 8, 2019
ad402e9
Prevent multiple patching of process
coreyfarrell Aug 8, 2019
159c190
Fix testing for future versions of nyc
coreyfarrell Aug 8, 2019
438495b
Use fs.mkdtempSync in tests
coreyfarrell Aug 9, 2019
1743a28
Implement fs.promises patching
coreyfarrell Aug 9, 2019
23ee88b
Add support for withFileTypes to readdir
coreyfarrell Aug 10, 2019
3e4abee
Fix code style issues that slipped in
coreyfarrell Aug 11, 2019
295c972
Emit ready event on stream open
coreyfarrell Aug 11, 2019
d108be7
Fix node.js 8 test issues
coreyfarrell Aug 11, 2019
32f2a75
Fix testing for node.js 10, set enumerable for gfs.promises
coreyfarrell Aug 11, 2019
4d8ddeb
Fix win32 testing
coreyfarrell Aug 12, 2019
7a7822a
Hide fs.close and fs.closeSync previous symbols
coreyfarrell Aug 14, 2019
1483484
Improve promises functionality
coreyfarrell Aug 15, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules/
coverage/
.nyc_output/
test/temp-files-*/
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ node_js:
- 12
- 10
- 8
- 6

os:
- linux
- windows
- osx
- linux

cache:
directories:
Expand Down
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ resilient to errors.
* Queues up `open` and `readdir` calls, and retries them once
something closes if there is an EMFILE error from too many file
descriptors.
* fixes `lchmod` for Node versions prior to 0.6.2.
* implements `fs.lutimes` if possible. Otherwise it becomes a noop.
* ignores `EINVAL` and `EPERM` errors in `chown`, `fchown` or
`lchown` if the user isn't root.
Expand Down Expand Up @@ -79,8 +78,7 @@ also imposes the challenge of keeping in sync with the core module.

The current approach loads the `fs` module, and then creates a
lookalike object that has all the same methods, except a few that are
patched. It is safe to use in all versions of Node from 0.8 through
7.0.
patched.

### v4

Expand Down
42 changes: 42 additions & 0 deletions check-for-callback.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
'use strict'

const nodeMajor = process.versions.node.split('.')[0]

/* This function emulates the functionality of node.js 7, 8 and 9 by emitting a
* deprecation warning. In node.js 10+ a TypeError is produced. */
function checkForCallback (cb, ctor) {
if (typeof cb === 'function') {
return true
}

if (nodeMajor >= 10) {
/* It's possible that the caller provided something incorrect for the callback
* but more likely they omitted the argument.
*
* The error is technically wrong if someone provides something for the callback
* argument which is not a function, for example `fs.mkdir('/path', {}, 'cb')`
* should say that a string was provided. Providing the correct exception for
* this off nominal case would require argument processing to be specific to each
* patched function. */
const error = new TypeError('Callback must be a function. Received undefined')
error.code = 'ERR_INVALID_CALLBACK'

/* The next 4 lines are copied from node.js, lib/internal/errors.js:addCodeToName() */
error.name = `${error.name} [${error.code}]`
Error.captureStackTrace(error, ctor)
error.stack // eslint-disable-line no-unused-expressions
delete error.name

throw error
}

process.emitWarning(
'Calling an asynchronous function without callback is deprecated.',
'DeprecationWarning',
'DEP0013',
ctor
)
return false
}

module.exports = checkForCallback
28 changes: 28 additions & 0 deletions chown-er-filter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'use strict'

// ENOSYS means that the fs doesn't support the op. Just ignore
// that, because it doesn't matter.
//
// if there's no getuid, or if getuid() is something other
// than 0, and the error is EINVAL or EPERM, then just ignore
// it.
//
// This specific case is a silent failure in cp, install, tar,
// and most other unix tools that manage permissions.
//
// When running as root, or if other types of errors are
// encountered, then it's strict.
function chownErFilter (er) {
if (!er || er.code === 'ENOSYS') {
return
}

const nonroot = !process.getuid || process.getuid() !== 0
if (nonroot && (er.code === 'EINVAL' || er.code === 'EPERM')) {
return
}

return er
}

module.exports = chownErFilter
12 changes: 3 additions & 9 deletions clone.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,11 @@
module.exports = clone

function clone (obj) {
if (obj === null || typeof obj !== 'object')
return obj
const copy = Object.create(Object.getPrototypeOf(obj))

if (obj instanceof Object)
var copy = { __proto__: obj.__proto__ }
else
var copy = Object.create(null)

Object.getOwnPropertyNames(obj).forEach(function (key) {
for (const key of Object.getOwnPropertyNames(obj)) {
Object.defineProperty(copy, key, Object.getOwnPropertyDescriptor(obj, key))
})
}

return copy
}
Loading