Skip to content

Commit 3468005

Browse files
committed
USB sync: make sure destination is writable
Change-Id: I9be82cac6000ba8683ef46d9d86331bee8f7821f
1 parent c818ba0 commit 3468005

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

assets/js/sync-to-drive.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,23 @@ class SyncToDrive {
9696
throw new Error('Error: USB device is not properly mounted.');
9797
}
9898

99-
log('Starting sync to USB drive ...');
100-
const distinationPath = path.join(device.mountpoint, this.destination);
101-
if (!fs.existsSync(distinationPath)) {
102-
log('Creating target directory' + distinationPath);
103-
fs.mkdirSync(distinationPath, { recursive: true });
99+
const destinationPath = path.join(device.mountpoint, this.destination);
100+
if (!fs.existsSync(destinationPath)) {
101+
log(`Creating target directory ${destinationPath}`);
102+
try {
103+
fs.mkdirSync(destinationPath, { recursive: true });
104+
} catch (err) {
105+
throw new Error(`Error: Failed to create directory ${destinationPath} - ${err.message}`);
106+
}
104107
}
105108

109+
if (!this.isWritable(destinationPath)) {
110+
throw new Error(`Error: Destination ${destinationPath} is not writable.`);
111+
}
112+
113+
log('Starting sync to USB drive ...');
106114
log('Source data folder ' + this.source);
107-
log('Syncing to drive ' + device.path + ' -> ' + distinationPath);
115+
log('Syncing to drive ' + device.path + ' -> ' + destinationPath);
108116

109117
const command = [
110118
'rsync',

0 commit comments

Comments
 (0)