Fixed various bugs in video copy and merge scripts
[videoscripts/.git] / move_videos_from_watchdir
index 83ec63fa50364c5678fba0cfd491a957f8da6c77..864d33e1c8265869001dd8202fc1ce33f37e0c2e 100755 (executable)
@@ -78,8 +78,14 @@ foreach $watchpath (split(';', $watchpathname)) {
        $srcfile = $file;
        $dstfile = "$dstpathname/$file";
 
+        # Make sure srcdir is group writable
+        if(not -w "$srcdir") {
+           print "-W- srcdir is not group writable, can't move videos out of it: $srcdir\n";
+           next;
+        } 
+
        # Make sure we have a unique dstfile
-       if(-f "$dstfile") {
+       if($overwrite_dest == 0 && -f "$dstfile") {
            $video_ext = $srcfile;
            $video_ext =~ s/.*\.(\S+)$/$1/;
            $suffix = 0;
@@ -96,18 +102,22 @@ foreach $watchpath (split(';', $watchpathname)) {
 
        if(!defined $opt_t) {
            # Make sure the dstfile doesn't exist, if it does, add a unique number to the end
-           if(! -f "$dstfile") {
-               $errno=system("mv \"$srcdir/$srcfile\" \"$dstfile\" 2>/dev/null");
-               if($errno) { print "-E- Error moving srcfile to dstfile: $srcdir/$srcfile -> $dstfile\n"; next; }
-           } else {
-               print "-E- Unable to mv $srcdir/$srcfile -> $dstfile because it already exists\n";
-           }
+           #if(! -f "$dstfile") {
+           $errno=system("mv \"$srcdir/$srcfile\" \"$dstfile\" 2>/dev/null");
+           if($errno) { print "-E- Error moving srcfile to dstfile: $srcdir/$srcfile -> $dstfile\n"; next; }
+           #} else {
+           #   print "-E- Unable to mv $srcdir/$srcfile -> $dstfile because it already exists\n";
+           #}
            # Fix the permissions
            system("chown $owner \"$dstfile\"");
            system("chgrp $group \"$dstfile\"");
            system("chmod $mode \"$dstfile\"");
        }
     }
+
+    # Update nextcloud file cache so it knows what files we have moved
+    $watchpath =~ s/$nextcloudbase//g;
+    system("$occ files:scan --path \"$watchpath\" > /dev/null");
 }
                    
 $pidfile->remove();