Sfoglia il codice sorgente

t4.pl: add a test to test that ignored file are not deleted

Olivier Goffart 11 anni fa
parent
commit
a73fbccf8c

+ 5 - 4
csync/src/csync_update.c

@@ -664,10 +664,6 @@ int csync_ftw(CSYNC *ctx, const char *uri, csync_walker_fn fn,
         /* If a directory has modified files, put the flag on the parent directory as well */
         previous_fs->child_modified = ctx->current_fs->child_modified;
     }
-    if (ctx->current_fs && previous_fs && ctx->current_fs->has_ignored_files) {
-        /* If a directory has ignored files, put the flag on the parent directory as well */
-        previous_fs->has_ignored_files = ctx->current_fs->has_ignored_files;
-    }
 
     /* Only for the local replica we have to destroy stat(), for the remote one it is a pointer to dirent */
     if (ctx->replica == LOCAL_REPLICA) {
@@ -696,6 +692,11 @@ int csync_ftw(CSYNC *ctx, const char *uri, csync_walker_fn fn,
         ctx->current_fs->instruction = CSYNC_INSTRUCTION_NONE;
         ctx->current_fs->should_update_etag = true;
       }
+
+      if (ctx->current_fs && previous_fs && ctx->current_fs->has_ignored_files) {
+          /* If a directory has ignored files, put the flag on the parent directory as well */
+          previous_fs->has_ignored_files = ctx->current_fs->has_ignored_files;
+      }
     }
 
     if (flag == CSYNC_FTW_FLAG_DIR && ctx->current_fs

+ 3 - 1
csync/tests/ownCloud/exclude.cfg

@@ -1 +1,3 @@
-*_conflict-*
+*.part
+]*.directory
+

+ 1 - 1
csync/tests/ownCloud/ownCloud/Test.pm

@@ -305,7 +305,7 @@ sub csync( ;$ )
 
     print "CSync URL: $url\n";
 
-    my $args = "--trust"; # Trust crappy SSL certificates
+    my $args = "--trust --exclude exclude.cfg"; # Trust crappy SSL certificates
     my $cmd = "LD_LIBRARY_PATH=$ld_libpath $csync $args $localDir $url";
     print "Starting: $cmd\n";
 

+ 17 - 1
csync/tests/ownCloud/t4.pl

@@ -38,6 +38,10 @@ printInfo( "Copy some files to the remote location" );
 mkdir( localDir() . 'test_stat' );
 system( "echo foobar > " . localDir() . 'test_stat/file.txt' );
 
+mkdir( localDir() . 'test_ignored' );
+mkdir( localDir() . 'test_ignored/sub' );
+system( "echo foobarfoo > " . localDir() . 'test_ignored/sub/file.txt' );
+
 # call csync, sync local t1 to remote t1
 csync();
 
@@ -91,15 +95,25 @@ my $realMD5 = md5OfFile( '/tmp/kernelcrash.txt' );
 print "MD5 compare $localMD5 <-> $realMD5\n";
 assert( $localMD5 eq $realMD5 );
 
-
 printInfo("Added a file that is on the ignore list");
 # (*.directory is in the ignored list that needs cleanup)
 # (it is names with _conflict) because i want the conflicft detection of assertLocalAndRemoteDir to work
 system( "echo dir >> " . localDir() . 'test_stat/file_conflict.directory' );
+# this one should retain the directory
+system( "echo foobarfoo > " . localDir() . 'test_ignored/sub/ignored_conflict.part' );
 csync();
 # The file_conflict.directory is seen as a conflict
 assertLocalAndRemoteDir( '', 1 );
 # TODO: check that the file_conflict.directory is indeed NOT on the server
+# TODO: check that test_ignored/sub/ignored_conflict.part is NOT on the server
+assert(-e localDir() . 'test_ignored/sub/ignored_conflict.part');
+
+printInfo("Remove a directory containing an ignored file that should not be removed\n");
+remoteCleanup('test_ignored');
+csync();
+assert(-e localDir() . 'test_ignored/sub/ignored_conflict.part');
+#remove the file so next sync allow the directory to be removed
+system( "rm " . localDir() . 'test_ignored/sub/ignored_conflict.part' );
 
 printInfo("Remove a directory containing a local file\n");
 remoteCleanup('test_stat');
@@ -150,6 +164,8 @@ printInfo("Now remove the symlink\n");
 system( "rm -f " . localDir() . 'anotherdir' );
 csync();
 assertLocalAndRemoteDir( '', 0 );
+assert(! -e localDir(). 'anotherdir' );
+
 
 cleanup();
 

+ 8 - 0
src/owncloudcmd/owncloudcmd.cpp

@@ -40,6 +40,7 @@ struct CmdOptions {
     QString proxy;
     bool silent;
     bool trustSSL;
+    QString exclude;
 };
 
 // we can't use csync_set_userdata because the SyncEngine sets it already.
@@ -76,6 +77,7 @@ void help()
     std::cout << "  --httpproxy = proxy:   Specify a http proxy to use." << std::endl;
     std::cout << "                         Proxy is http://server:port" << std::endl;
     std::cout << "  --trust                Trust the SSL certification." << std::endl;
+    std::cout << "  --exclude [file]       exclude list file" << std::endl;
     std::cout << "" << std::endl;
     exit(1);
 
@@ -120,6 +122,8 @@ void parseOptions( const QStringList& app_args, CmdOptions *options )
             options->silent = true;
         } else if( option == "--trust") {
             options->trustSSL = true;
+        } else if( option == "--exclude" && !it.peekNext().startsWith("-") ) {
+                options->exclude = it.next();
         } else {
             help();
         }
@@ -214,6 +218,10 @@ int main(int argc, char **argv) {
         clientProxy.setCSyncProxy(QUrl(url), _csync_ctx);
     }
 
+    if (!options.exclude.isEmpty()) {
+        csync_add_exclude_list(_csync_ctx, options.exclude.toLocal8Bit());
+    }
+
     OwncloudCmd owncloudCmd;
 
     SyncJournalDb db(options.source_dir);