Updated for Ubuntu 22.04. Also fixed merge videos cmin check
[videoscripts/.git] / move_videos_from_watchdir
index 364ade6575180ba5644e87ada1a9ba7db8f0238d..864d33e1c8265869001dd8202fc1ce33f37e0c2e 100755 (executable)
@@ -85,7 +85,7 @@ foreach $watchpath (split(';', $watchpathname)) {
         } 
 
        # 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;
@@ -102,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();