Skip to content

Commit

Permalink
fix permission setting for memex desktop
Browse files Browse the repository at this point in the history
  • Loading branch information
blackforestboi committed Mar 4, 2024
1 parent 3335d65 commit e786e10
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:

strategy:
matrix:
os: [macos-latest-xlarge, ubuntu-latest, windows-latest]
os: [macos-latest, ubuntu-latest, windows-latest]

steps:
- name: Check out Git repository
Expand Down
21 changes: 21 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,7 @@ expressApp.put('/backup/:collection/:timestamp', async (req, res) => {
if (!checkSyncKey(req.body.syncKey)) {
return res.status(403).send('Only one app instance allowed')
}

var filename = req.params.timestamp
if (!isPathComponentValid(filename)) {
return res.status(400).send('Malformed timestamp parameter')
Expand All @@ -649,11 +650,31 @@ expressApp.put('/backup/:collection/:timestamp', async (req, res) => {
}

var filepath = dirpath + `/${filename}`
console.log('filepath', filepath)

fs.access(dirpath, fs.constants.W_OK, (err) => {
if (err) {
console.log('not writeable', err)
// Adjust permissions in a cross-platform manner
fs.chmod(dirpath, 0o766, (chmodErr) => {
// Sets read, write, and execute permissions for the owner, and read/write for group and others
if (chmodErr) {
console.error(`Failed to adjust permissions:`, chmodErr)
} else {
console.log(`${dirpath} permissions adjusted.`)
}
})
} else {
console.log(`${filepath} is writable.`)
}
})
fs.writeFile(filepath, JSON.stringify(req.body), function (err) {
if (err) {
log.error(err)
console.log('err', err)
return res.status(500).send('Failed to write to file.')
}
console.log('File written successfully')
res.status(200).send('Data saved successfully.')
})
})

0 comments on commit e786e10

Please sign in to comment.