Skip to content

Commit

Permalink
fix: permission denied when mkdirp
Browse files Browse the repository at this point in the history
# Problems
- Error: EACCES: permission denied, open '{path}'

# Solution
- From: https://stackoverflow.com/a/34721366
- The documentation states that the default is 0777 & (~process.umask())
which means that your umask value is "subtracted" from the 0777.
Since the umask commonly is 002 or 022, you end up with 0775 or 0755.
- To prevent that, you need to clear the umask (process.umask(0))
  • Loading branch information
Chinlinlee committed Mar 17, 2023
1 parent 45ea880 commit 2110324
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions api/dicom-web/stow/service/stow.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,17 @@ async function storeBinaryDataAndReplaceToUri(req, uidObj, dicomJson) {
process.env.DICOM_STORE_ROOTPATH,
relativeFilename
);

let oldMask = process.umask(0);
mkdirp.sync(
path.join(
process.env.DICOM_STORE_ROOTPATH,
`files/bulkData/${shortInstanceUID}`
)
),
"0755"
);
process.umask(oldMask);

logger.info(`[STOW-RS] [Store binary data to ${filename}]`);
fs.writeFileSync(filename, Buffer.from(binaryData, "base64"));

Expand Down Expand Up @@ -582,7 +587,11 @@ async function stow(req, filename, originalFilename) {

let { relativeStorePath, fullStorePath, metadataFullStorePath } =
getStoreDest(dicomJsonAndBigTags.dicomJson);
mkdirp.sync(fullStorePath, 0x755);

let oldMask = process.umask(0);
mkdirp.sync(fullStorePath, "0755");
process.umask(oldMask);

storeMetadataToDisk(dicomJsonAndBigTags, metadataFullStorePath);


Expand Down

0 comments on commit 2110324

Please sign in to comment.