forked from natcap/invest
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request natcap#1279 from davemfish/bugfix/WB-1070-download…
…-permissions Error-handling for sampledata downloading in workbench
- Loading branch information
Showing
8 changed files
with
120 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
|
||
import { | ||
ipcMain, | ||
} from 'electron'; | ||
|
||
import { ipcMainChannels } from './ipcMainChannels'; | ||
import { getLogger } from './logger'; | ||
|
||
const logger = getLogger(__filename.split('/').slice(-1)[0]); | ||
|
||
export default function setupCheckFilePermissions() { | ||
ipcMain.handle( | ||
ipcMainChannels.CHECK_FILE_PERMISSIONS, (event, folder) => { | ||
const filepath = path.join(folder, 'foo.txt'); | ||
let writeable; | ||
try { | ||
// The only reliable way to determine if a folder is writeable | ||
// is to write to it. https://github.com/nodejs/node/issues/2949 | ||
fs.writeFileSync(filepath, ''); | ||
writeable = true; | ||
} catch (err) { | ||
writeable = false; | ||
logger.debug(err); | ||
} finally { | ||
fs.rm(filepath, (err) => logger.debug(err)); | ||
} | ||
return writeable; | ||
} | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters