Skip to content

Commit

Permalink
Persistence: prevent NPM from overwriting node_modules by setting rea…
Browse files Browse the repository at this point in the history
…d-only attribute on the persisted directory junction.
  • Loading branch information
lukesampson committed Mar 24, 2017
1 parent 2a34d13 commit 4382206
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
3 changes: 2 additions & 1 deletion bucket/nodejs.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
}
},
"env_add_path": "nodejs",
"persist": "nodejs/node_modules",
"post_install": "
# Remove npmrc that makes global modules get installed in AppData\\Roaming\\npm
rm $dir\\nodejs\\node_modules\\npm\\npmrc
if(test-path $dir\\nodejs\\node_modules\\npm\\npmrc) { rm $dir\\nodejs\\node_modules\\npm\\npmrc }
npm update -g",
"checkver": {
"url": "https://nodejs.org/en/download/current/",
Expand Down
9 changes: 5 additions & 4 deletions lib/install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -976,19 +976,19 @@ function persist_def($persist) {
function persist_data($manifest) {
$persist = $manifest.persist
if($persist) {
ensure $data_dir
$data_dir = ensure $data_dir

This comment has been minimized.

Copy link
@lukesampson

lukesampson Mar 24, 2017

Author Member

I think this logs the directory to the console if you don't reassign it.


if ($persist -is [String]) {
$persist = @($persist);
}

write-host "Persisting data..."
write-host "Persisting $persist"
$persist | % {
$source, $target = persist_def $_

# add base paths
$source = "$original_dir\$source"
$target = "$data_dir\$target"
$source = "$(resolve-path $original_dir\$source)"

This comment has been minimized.

Copy link
@lukesampson

lukesampson Mar 24, 2017

Author Member

I changed this because I think something had trouble with the forward slash I used for persist in the manifest.

$target = fullpath "$data_dir\$target"

This comment has been minimized.

Copy link
@lukesampson

lukesampson Mar 24, 2017

Author Member

Similar to above.


# TODO test with files
if (!(test-path $target)) {
Expand All @@ -1007,6 +1007,7 @@ function persist_data($manifest) {
# create link
# TODO use /h for files
cmd /c "mklink /j $source $target" | out-null
attrib $source +R /L #

This comment has been minimized.

Copy link
@lukesampson

lukesampson Mar 24, 2017

Author Member

The magic line. +R adds a read-only attribute, and /L applies it to the symlink rather than the target of the symlink.

Documentation for attrib is here. /L isn't listed in the Windows XP documentation for Attrib, so I'm not sure how well supported this is.

}
}
}

0 comments on commit 4382206

Please sign in to comment.