[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdelibs/kio
From:       David Faure <faure () kde ! org>
Date:       2010-03-11 23:45:53
Message-ID: 1268351153.262795.3422.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 1102172 by dfaure:

Add support for KIO::Overwrite in CopyJob, Lubos isn't the first one to be surprised \
by that not being there.


 M  +4 -0      kio/copyjob.cpp  
 M  +34 -14    kio/copyjob.h  
 M  +17 -6     tests/jobtest.cpp  


--- trunk/KDE/kdelibs/kio/kio/copyjob.cpp #1102171:1102172
@@ -235,6 +235,10 @@
         job->setUiDelegate(new JobUiDelegate);
         if (!(flags & HideProgressInfo))
             KIO::getJobTracker()->registerJob(job);
+        if (flags & KIO::Overwrite) {
+            job->d_func()->m_bOverwriteAllDirs = true;
+            job->d_func()->m_bOverwriteAllFiles = true;
+        }
         return job;
     }
 };
--- trunk/KDE/kdelibs/kio/kio/copyjob.h #1102171:1102172
@@ -266,7 +266,11 @@
      *
      * @param src the file or directory to copy
      * @param dest the destination
-     * @param flags: We support HideProgressInfo here
+     * @param flags: copy() supports HideProgressInfo and Overwrite.
+     * Note: Overwrite has the meaning of both "write into existing directories" and
+     * "overwrite existing files". However if "dest" exists, then src is copied
+     * into a subdir of dest, just like "cp" does. Use copyAs if you don't want \
that. +     *
      * @return the job handling the operation
      * @see copyAs()
      */
@@ -278,12 +282,16 @@
      *
      * As opposed to copy(), this doesn't emulate cp, but is the only
      * way to copy a directory, giving it a new name and getting an error
-     * box if a directory already exists with the same name.
+     * box if a directory already exists with the same name (or writing the
+     * contents of @p src into @p dest, when using Overwrite).
      *
      * @param src the file or directory to copy
      * @param dest the destination
-     * @param flags: We support HideProgressInfo here
-     * @return the job handling the operation
+     * @param flags: copyAs() supports HideProgressInfo and Overwrite.
+     * Note: Overwrite has the meaning of both "write into existing directories" and
+     * "overwrite existing files".
+     *
+     * * @return the job handling the operation
      */
     KIO_EXPORT CopyJob *copyAs( const KUrl& src, const KUrl& dest, JobFlags flags = \
DefaultFlags );  
@@ -292,7 +300,10 @@
      *
      * @param src the list of files and/or directories
      * @param dest the destination
-     * @param flags: We support HideProgressInfo here
+     * @param flags: copy() supports HideProgressInfo and Overwrite.
+     * Note: Overwrite has the meaning of both "write into existing directories" and
+     * "overwrite existing files". However if "dest" exists, then src is copied
+     * into a subdir of dest, just like "cp" does.
      * @return the job handling the operation
      */
     KIO_EXPORT CopyJob *copy( const KUrl::List& src, const KUrl& dest, JobFlags \
flags = DefaultFlags ); @@ -302,7 +313,10 @@
      *
      * @param src the file or directory to copy
      * @param dest the destination
-     * @param flags: We support HideProgressInfo here
+     * @param flags: move() supports HideProgressInfo and Overwrite.
+     * Note: Overwrite has the meaning of both "write into existing directories" and
+     * "overwrite existing files". However if "dest" exists, then src is copied
+     * into a subdir of dest, just like "cp" does.
      * @return the job handling the operation
      * @see copy()
      * @see moveAs()
@@ -310,11 +324,14 @@
     KIO_EXPORT CopyJob *move( const KUrl& src, const KUrl& dest, JobFlags flags = \
DefaultFlags );  /**
      * Moves a file or directory @p src to the given destination @p dest. Unlike \
                move()
-     * this operation will fail when the directory already exists.
+     * this operation will not move @p src into @p dest when @p dest exists: it will
+     * either fail, or move the contents of @p src into it if Overwrite is set.
      *
      * @param src the file or directory to copy
      * @param dest the destination
-     * @param flags: We support HideProgressInfo here
+     * @param flags: moveAs() supports HideProgressInfo and Overwrite.
+     * Note: Overwrite has the meaning of both "write into existing directories" and
+     * "overwrite existing files".
      * @return the job handling the operation
      * @see copyAs()
      */
@@ -324,7 +341,10 @@
      *
      * @param src the list of files or directories to copy
      * @param dest the destination
-     * @param flags: We support HideProgressInfo here
+     * @param flags: move() supports HideProgressInfo and Overwrite.
+     * Note: Overwrite has the meaning of both "write into existing directories" and
+     * "overwrite existing files". However if "dest" exists, then src is copied
+     * into a subdir of dest, just like "cp" does.
      * @return the job handling the operation
      * @see copy()
      */
@@ -337,7 +357,7 @@
      *
      * @param src The existing file or directory, 'target' of the link.
      * @param destDir Destination directory where the link will be created.
-     * @param flags: We support HideProgressInfo here
+     * @param flags: link() supports HideProgressInfo only
      * @return the job handling the operation
      */
     KIO_EXPORT CopyJob *link( const KUrl& src, const KUrl& destDir, JobFlags flags = \
DefaultFlags ); @@ -349,7 +369,7 @@
      *
      * @param src The existing files or directories, 'targets' of the link.
      * @param destDir Destination directory where the links will be created.
-     * @param flags: We support HideProgressInfo here
+     * @param flags: link() supports HideProgressInfo only
      * @return the job handling the operation
      * @see link()
      */
@@ -363,7 +383,7 @@
      *
      * @param src The existing file or directory, 'target' of the link.
      * @param dest Destination directory where the link will be created.
-     * @param flags: We support HideProgressInfo here
+     * @param flags: linkAs() supports HideProgressInfo only
      * @return the job handling the operation
      * @see link ()
      * @see copyAs()
@@ -376,7 +396,7 @@
      * Use "KUrl src; src.setPath( path );" to create a URL from a path.
      *
      * @param src file to delete
-     * @param flags: We support HideProgressInfo here
+     * @param flags: trash() supports HideProgressInfo only
      * @return the job handling the operation
      */
     KIO_EXPORT CopyJob *trash( const KUrl& src, JobFlags flags = DefaultFlags );
@@ -386,7 +406,7 @@
      * This is currently only supported for local files and directories.
      *
      * @param src the files to delete
-     * @param flags: We support HideProgressInfo here
+     * @param flags: trash() supports HideProgressInfo only
      * @return the job handling the operation
      */
     KIO_EXPORT CopyJob *trash( const KUrl::List& src, JobFlags flags = DefaultFlags \
                );
--- trunk/KDE/kdelibs/kio/tests/jobtest.cpp #1102171:1102172
@@ -322,6 +322,19 @@
         QCOMPARE( srcInfo.lastModified(), destInfo.lastModified() );
     }
 #endif
+
+    // Do it again, with Overwrite.
+    // Use copyAs, we don't want a subdir inside d.
+    job = KIO::copyAs(u, d, KIO::HideProgressInfo | KIO::Overwrite);
+    job->setUiDelegate(0);
+    ok = KIO::NetAccess::synchronousRun(job, 0);
+    QVERIFY( ok );
+
+    // Do it again, without Overwrite (should fail).
+    job = KIO::copyAs(u, d, KIO::HideProgressInfo);
+    job->setUiDelegate(0);
+    ok = KIO::NetAccess::synchronousRun(job, 0);
+    QVERIFY( !ok );
 }
 
 void JobTest::copyFileToSamePartition()
@@ -345,11 +358,12 @@
 void JobTest::copyDirectoryToExistingDirectory()
 {
     kDebug() ;
-    // just the same as copyDirectoryToSamePartition, but it means that
-    // this time dest exists.
+    // just the same as copyDirectoryToSamePartition, but this time dest exists.
+    // So we get a subdir, "dirFromHome_copy/dirFromHome"
     const QString src = homeTmpDir() + "dirFromHome";
     const QString dest = homeTmpDir() + "dirFromHome_copied";
     createTestDirectory( src );
+    createTestDirectory( dest );
     copyLocalDirectory( src, dest, AlreadyExists );
 }
 
@@ -367,10 +381,7 @@
     kDebug() ;
     const QString src = homeTmpDir() + "dirFromHome";
     const QString dest = otherTmpDir() + "dirFromHome_copied";
-    // src is already created by copyDirectoryToSamePartition()
-    // so this is just in case someone calls this method only
-    if ( !QFile::exists( src ) )
-        createTestDirectory( src );
+    createTestDirectory( src );
     copyLocalDirectory( src, dest );
 }
 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic