Skip to content

Commit 4131196

Browse files
rmgzkat
authored andcommitted
fix(content): make verified content completely read-only (#96)
The only non-corrupting modification to content stored in cacache is to delete it, and that requires write permission on the containing directory rather than on the file itself. Since no valid operations require write permissions on the content files, mark them as read-only so that the rest of the OS knows these files aren't meant to be written to. Fixes: #95 Signed-off-by: Ryan Graham <[email protected]>
1 parent 5e04eb7 commit 4131196

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

Diff for: lib/util/move-file.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
const fs = require('graceful-fs')
44
const BB = require('bluebird')
5+
const chmod = BB.promisify(fs.chmod)
6+
const unlink = BB.promisify(fs.unlink)
57
let move
68
let pinflight
79

@@ -27,8 +29,11 @@ function moveFile (src, dest) {
2729
return cb(err)
2830
}
2931
}
30-
return fs.unlink(src, cb)
32+
return cb()
3133
})
34+
}).then(() => {
35+
// content should never change for any reason, so make it read-only
36+
return BB.join(unlink(src), process.platform !== 'win32' && chmod(dest, '0444'))
3237
}).catch(err => {
3338
if (process.platform !== 'win32') {
3439
throw err

0 commit comments

Comments
 (0)