-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
Expand file tree
/
Copy pathtest-fs-long-path.js
More file actions
46 lines (40 loc) · 1.28 KB
/
test-fs-long-path.js
File metadata and controls
46 lines (40 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
'use strict';
const common = require('../common');
const fs = require('fs');
const path = require('path');
const os = require('os');
// when it fails test again under real OS tmp dir on Linux when it is
// readable/writable to avoid failing tests on ecryptfs filesystems:
// https://github.com/nodejs/node/issues/2255
// it follows advice in comments to:
// https://github.com/nodejs/node/pull/3925
// https://github.com/nodejs/node/pull/3929
try {
common.refreshTmpDir();
testFsLongPath(common.tmpDir);
common.refreshTmpDir();
} catch (e) {
if (process.platform == 'linux') {
fs.accessSync(os.tmpdir(), fs.R_OK | fs.W_OK);
const tmpDir = path.join(os.tmpdir(),
`node-${process.version}-test-${1e6 * Math.random() | 0}`);
fs.mkdirSync(tmpDir);
testFsLongPath(tmpDir);
fs.rmdirSync(tmpDir);
} else {
throw e;
}
}
function testFsLongPath(tmpDir) {
// make a path that will be at least 260 chars long.
const fileNameLen = Math.max(260 - tmpDir.length - 1, 1);
const fileName = path.join(tmpDir, new Array(fileNameLen + 1).join('x'));
const fullPath = path.resolve(fileName);
console.log({
filenameLength: fileName.length,
fullPathLength: fullPath.length
});
fs.writeFileSync(fullPath, 'ok');
fs.statSync(fullPath);
fs.unlinkSync(fullPath);
}