-
-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: implement lutimes * fix: lutimes/lutimesSync not exported on fs
- Loading branch information
1 parent
18f4abe
commit a1772b2
Showing
4 changed files
with
90 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { create } from '../util'; | ||
|
||
describe('lutimesSync', () => { | ||
it('should be able to lutimes symlinks regardless of their permissions', () => { | ||
const perms = [ | ||
0o777, // rwx | ||
0o666, // rw | ||
0o555, // rx | ||
0o444, // r | ||
0o333, // wx | ||
0o222, // w | ||
0o111, // x | ||
0o000, // none | ||
]; | ||
// Check for directories | ||
perms.forEach(perm => { | ||
const vol = create({ '/target': 'test' }); | ||
vol.symlinkSync('/target', '/test'); | ||
expect(() => { | ||
vol.lutimesSync('/test', 0, 0); | ||
}).not.toThrow(); | ||
}); | ||
}); | ||
|
||
it('should set atime and mtime on the link itself, not the target', () => { | ||
const vol = create({ '/target': 'test' }); | ||
vol.symlinkSync('/target', '/test'); | ||
vol.lutimesSync('/test', new Date(1), new Date(2)); | ||
const linkStats = vol.lstatSync('/test'); | ||
const targetStats = vol.statSync('/target'); | ||
|
||
expect(linkStats.atime).toEqual(new Date(1)); | ||
expect(linkStats.mtime).toEqual(new Date(2)); | ||
|
||
expect(targetStats.atime).not.toEqual(new Date(1)); | ||
expect(targetStats.mtime).not.toEqual(new Date(2)); | ||
}); | ||
|
||
it("should throw ENOENT when target doesn't exist", () => { | ||
const vol = create({ '/target': 'test' }); | ||
// Don't create symlink this time | ||
expect(() => { | ||
vol.lutimesSync('/test', 0, 0); | ||
}).toThrow(/ENOENT/); | ||
}); | ||
|
||
it('should throw EACCES when containing directory has insufficient permissions', () => { | ||
const vol = create({ '/target': 'test' }); | ||
vol.mkdirSync('/foo'); | ||
vol.symlinkSync('/target', '/foo/test'); | ||
vol.chmodSync('/foo', 0o666); // rw | ||
expect(() => { | ||
vol.lutimesSync('/foo/test', 0, 0); | ||
}).toThrow(/EACCES/); | ||
}); | ||
|
||
it('should throw EACCES when intermediate directory has insufficient permissions', () => { | ||
const vol = create({ '/target': 'test' }); | ||
vol.mkdirSync('/foo'); | ||
vol.symlinkSync('/target', '/foo/test'); | ||
vol.chmodSync('/', 0o666); // rw | ||
expect(() => { | ||
vol.lutimesSync('/foo/test', 0, 0); | ||
}).toThrow(/EACCES/); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters