-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fs: adjust truncate mode from
r+
to a
- Loading branch information
1 parent
8bf7754
commit 375f0a7
Showing
5 changed files
with
74 additions
and
15 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
|
||
// This test ensures that truncate works on non-readable files | ||
|
||
const assert = require('assert'); | ||
const fs = require('fs'); | ||
const fsPromises = fs.promises; | ||
const path = require('path'); | ||
const tmpdir = require('../common/tmpdir'); | ||
tmpdir.refresh(); | ||
|
||
const expected = Buffer.from('good'); | ||
|
||
function checkContents(filepath) { | ||
fs.chmodSync(filepath, 0o400); | ||
assert.deepStrictEqual( | ||
fs.readFileSync(filepath), | ||
expected | ||
); | ||
} | ||
|
||
(async () => { | ||
const MODE = 0o200; | ||
{ | ||
const filepath = path.resolve(tmpdir.path, 'promises.txt'); | ||
fs.writeFileSync(filepath, 'good bad'); | ||
fs.chmodSync(filepath, MODE); | ||
await fsPromises.truncate(filepath, 4); | ||
checkContents(filepath); | ||
} | ||
{ | ||
const filepath = path.resolve(tmpdir.path, 'callback.txt'); | ||
fs.writeFileSync(filepath, 'good bad'); | ||
fs.chmodSync(filepath, MODE); | ||
fs.truncate(filepath, 4, common.mustSucceed(() => { | ||
checkContents(filepath); | ||
})); | ||
} | ||
{ | ||
const filepath = path.resolve(tmpdir.path, 'synchronous.txt'); | ||
fs.writeFileSync(filepath, 'good bad'); | ||
fs.chmodSync(filepath, MODE); | ||
fs.truncateSync(filepath, 4); | ||
checkContents(filepath); | ||
} | ||
})().then(common.mustCall()); |
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