@@ -110,25 +110,33 @@ class SyncToDrive {
110110 throw new Error ( `Error: Destination ${ destinationPath } is not writable.` ) ;
111111 }
112112
113- log ( 'Starting sync to USB drive ...' ) ;
114- log ( 'Source data folder ' + this . source ) ;
115- log ( 'Syncing to drive ' + device . path + ' -> ' + destinationPath ) ;
116-
117113 const command = [
118114 'rsync' ,
119115 '-a' ,
120- '--delete-before' ,
121116 '-b' ,
117+ '--delete-before' ,
122118 '--backup-dir=' + path . join ( device . mountpoint , 'deleted' ) ,
123119 '--ignore-existing' ,
124- '--include=\'*.\' {jpg,chk,gif,mp4}' ,
120+ '--include=\'*.{jpg,chk,gif,mp4}\' ' ,
125121 '--include=\'*/\'' ,
126122 '--exclude=\'*\'' ,
127123 '--prune-empty-dirs' ,
128124 this . source ,
129- path . join ( device . mountpoint , this . destination )
125+ destinationPath
130126 ] . join ( ' ' ) ;
131- log ( 'Executing command "' + command + '"' ) ;
127+
128+ log ( 'Validating rsync command...' ) ;
129+ try {
130+ execSync ( command + ' --dry-run' , { stdio : 'ignore' } ) ;
131+ // eslint-disable-next-line no-unused-vars
132+ } catch ( err ) {
133+ throw new Error ( 'Error: Rsync validation failed. Check permissions and paths.' ) ;
134+ }
135+
136+ log ( 'Starting sync to USB drive ...' ) ;
137+ log ( 'Source data folder ' + this . source ) ;
138+ log ( 'Syncing to drive ' + device . path + ' -> ' + destinationPath ) ;
139+ log ( `Executing command: "${ command } "` ) ;
132140
133141 this . rsyncProcess = spawn ( command , {
134142 shell : '/bin/bash'
@@ -140,8 +148,7 @@ class SyncToDrive {
140148 } ) ;
141149 this . rsyncProcess . on ( 'exit' , ( ) => {
142150 this . rsyncProcess = null ;
143- log ( 'Sync finished' ) ;
144- log ( 'Next run in ' + this . intervalInSeconds + 's' ) ;
151+ log ( 'Sync finished. Next run in ' + this . intervalInSeconds + 's' ) ;
145152 setTimeout ( ( ) => {
146153 this . start ( ) ;
147154 } , this . intervalInMilliseconds ) ;
0 commit comments