forked from isaacs/node-tar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget-write-flag.js
More file actions
78 lines (71 loc) · 1.81 KB
/
Copy pathget-write-flag.js
File metadata and controls
78 lines (71 loc) · 1.81 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import fs from 'fs'
import t from 'tap'
import { fileURLToPath } from 'url'
import { getWriteFlag } from '../dist/esm/get-write-flag.js'
const __filename = fileURLToPath(import.meta.url)
// run three scenarios
// unix (no fmap)
// win32 (without fmap support)
// win32 (with fmap support)
const hasFmap = !!fs.constants.UV_FS_O_FILEMAP
const { platform } = process
const UV_FS_O_FILEMAP = 0x20000000
const unixFlag =
typeof fs.constants.O_NOFOLLOW === 'number' ?
fs.constants.O_NOFOLLOW |
fs.constants.O_TRUNC |
fs.constants.O_CREAT |
fs.constants.O_WRONLY
: 'w'
switch (process.argv[2]) {
case 'win32-fmap': {
const { O_CREAT, O_TRUNC, O_WRONLY } = fs.constants
t.equal(
getWriteFlag(1),
UV_FS_O_FILEMAP | O_TRUNC | O_CREAT | O_WRONLY,
)
t.equal(getWriteFlag(512 * 1024 + 1), 'w')
break
}
case 'win32-nofmap': {
t.equal(getWriteFlag(1), 'w')
t.equal(getWriteFlag(512 * 1024 + 1), 'w')
break
}
case 'unix': {
t.equal(getWriteFlag(1), unixFlag)
t.equal(getWriteFlag(512 * 1024 + 1), unixFlag)
break
}
default: {
const node = process.execPath
t.spawn(node, [__filename, 'win32-fmap'], {
env: {
...process.env,
...(platform === 'win32' ?
{}
: {
__FAKE_FS_O_FILENAME__: String(UV_FS_O_FILEMAP),
__FAKE_PLATFORM__: 'win32',
}),
},
})
t.spawn(node, [__filename, 'win32-nofmap'], {
env: {
...process.env,
...(platform === 'win32' ?
{}
: {
__FAKE_FS_O_FILENAME__: '0',
__FAKE_PLATFORM__: 'win32',
}),
},
})
t.spawn(node, [__filename, 'unix'], {
env: {
...process.env,
...(platform === 'win32' ? { __FAKE_PLATFORM__: 'linux' } : {}),
},
})
}
}