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

List:       kde-commits
Subject:    branches/KDE/3.5/kdelibs
From:       David Faure <faure () kde ! org>
Date:       2005-08-28 8:28:35
Message-ID: 1125217715.030771.16369.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 454163 by dfaure:

Fix moving of broken symlinks. Happens more often than one might think, e.g.
when moving an entire directory with both a link and its destination in the dir,
and the destination gets moved first; this gives a temporarily broken symlink,
which still has to be moved without errors. Should fix kimdaba uploading.
CCMAIL: blackie@blackie.dk


 M  +60 -3     kio/tests/jobtest.cpp  
 M  +1 -0      kio/tests/jobtest.h  
 M  +5 -7      kioslave/file/file.cc  


--- branches/KDE/3.5/kdelibs/kio/tests/jobtest.cpp #454162:454163
@@ -23,17 +23,21 @@
 
 #include <kurl.h>
 #include <kapplication.h>
+#include <klargefile.h>
 #include <kio/netaccess.h>
 #include <kdebug.h>
 #include <kcmdlineargs.h>
 
 #include <qfileinfo.h>
 #include <qeventloop.h>
+#include <qdir.h>
+#include <qfileinfo.h>
 
 #include <stdio.h>
 #include <stdlib.h>
 #include <assert.h>
-#include <qdir.h>
+#include <unistd.h>
+#include <errno.h>
 
 // The code comes partly from kdebase/kioslave/trash/testtrash.cpp
 
@@ -102,6 +106,7 @@
     moveFileToSamePartition();
     moveDirectoryToSamePartition();
     moveFileToOtherPartition();
+    moveSymlinkToOtherPartition();
     moveDirectoryToOtherPartition();
     moveFileNoPermissions();
     moveDirectoryNoPermissions();
@@ -122,6 +127,17 @@
     f.close();
 }
 
+static void createTestSymlink( const QString& path )
+{
+    // Create symlink if it doesn't exist yet
+    KDE_struct_stat buf;
+    if ( KDE_lstat( QFile::encodeName( path ), &buf ) != 0 ) {
+        bool ok = symlink( "/IDontExist", QFile::encodeName( path ) ) == 0; // \
broken symlink +        if ( !ok )
+            kdFatal() << "couldn't create symlink: " << strerror( errno ) << endl;
+    }
+}
+
 static void createTestDirectory( const QString& path )
 {
     QDir dir;
@@ -129,6 +145,7 @@
     if ( !ok && !dir.exists() )
         kdFatal() << "couldn't create " << path << endl;
     createTestFile( path + "/testfile" );
+    createTestSymlink( path + "/testlink" );
 }
 
 void JobTest::get()
@@ -251,11 +268,36 @@
     assert( QFile::exists( src ) ); // it's back
 }
 
+static void moveLocalSymlink( const QString& src, const QString& dest )
+{
+    KDE_struct_stat buf;
+    assert ( KDE_lstat( QFile::encodeName( src ), &buf ) == 0 );
+    KURL u;
+    u.setPath( src );
+    KURL d;
+    d.setPath( dest );
+
+    // move the symlink with move, NOT with file_move
+    bool ok = KIO::NetAccess::move( u, d );
+    if ( !ok )
+        kdWarning() << KIO::NetAccess::lastError() << endl;
+    assert( ok );
+    assert ( KDE_lstat( QFile::encodeName( dest ), &buf ) == 0 );
+    assert( !QFile::exists( src ) ); // not there anymore
+
+    // move it back with KIO::move()
+    ok = KIO::NetAccess::move( d, u, 0 );
+    assert( ok );
+    assert ( KDE_lstat( QFile::encodeName( dest ), &buf ) != 0 ); // doesn't exist \
anymore +    assert ( KDE_lstat( QFile::encodeName( src ), &buf ) == 0 ); // it's \
back +}
+
 void JobTest::moveLocalDirectory( const QString& src, const QString& dest )
 {
     assert( QFile::exists( src ) );
     assert( QFileInfo( src ).isDir() );
     assert( QFileInfo( src + "/testfile" ).isFile() );
+    assert( QFileInfo( src + "/testlink" ).isSymLink() );
     KURL u;
     u.setPath( src );
     KURL d;
@@ -267,6 +309,8 @@
     assert( QFileInfo( dest ).isDir() );
     assert( QFileInfo( dest + "/testfile" ).isFile() );
     assert( !QFile::exists( src ) ); // not there anymore
+
+    assert( QFileInfo( dest + "/testlink" ).isSymLink() );
 }
 
 void JobTest::moveFileToSamePartition()
@@ -296,11 +340,20 @@
     moveLocalFile( filePath, dest );
 }
 
+void JobTest::moveSymlinkToOtherPartition()
+{
+    kdDebug() << k_funcinfo << endl;
+    const QString filePath = homeTmpDir() + "testlink";
+    const QString dest = otherTmpDir() + "testlink_moved";
+    createTestSymlink( filePath );
+    moveLocalSymlink( filePath, dest );
+}
+
 void JobTest::moveDirectoryToOtherPartition()
 {
     kdDebug() << k_funcinfo << endl;
     const QString src = homeTmpDir() + "dirFromHome";
-    const QString dest = homeTmpDir() + "dirFromHome_moved";
+    const QString dest = otherTmpDir() + "dirFromHome_moved";
     createTestDirectory( src );
     moveLocalDirectory( src, dest );
 }
@@ -365,7 +418,11 @@
     bool ok = KIO::NetAccess::synchronousRun( job, 0 );
     assert( ok );
     m_names.sort();
-    check( "listRecursive", m_names.join( "," ), \
".,..,dirFromHome,dirFromHome/testfile,dirFromHome_copied,dirFromHome_copied/dirFromHo \
me,dirFromHome_copied/dirFromHome/testfile,dirFromHome_copied/testfile,fileFromHome,fileFromHome_copied" \
); +    check( "listRecursive", m_names.join( "," ), ".,..,"
+            "dirFromHome,dirFromHome/testfile,dirFromHome/testlink,dirFromHome_copied,"
 +            "dirFromHome_copied/dirFromHome,dirFromHome_copied/dirFromHome/testfile,dirFromHome_copied/dirFromHome/testlink,"
 +            "dirFromHome_copied/testfile,dirFromHome_copied/testlink,"
+            "fileFromHome,fileFromHome_copied" );
 }
 
 void JobTest::slotEntries( KIO::Job*, const KIO::UDSEntryList& lst )
--- branches/KDE/3.5/kdelibs/kio/tests/jobtest.h #454162:454163
@@ -44,6 +44,7 @@
     void moveFileToSamePartition();
     void moveDirectoryToSamePartition();
     void moveFileToOtherPartition();
+    void moveSymlinkToOtherPartition();
     void moveDirectoryToOtherPartition();
     void moveFileNoPermissions();
     void moveDirectoryNoPermissions();
--- branches/KDE/3.5/kdelibs/kioslave/file/file.cc #454162:454163
@@ -390,7 +390,7 @@
 
                 if ( fd < 0 )
                 {
-                    kdDebug(7101) << "####################### COULD NOT WRITE " << \
dest << _mode << endl; +                    kdDebug(7101) << "####################### \
                COULD NOT WRITE " << dest << " _mode=" << _mode << endl;
                     kdDebug(7101) << "errno==" << errno << "(" << strerror(errno) << \
")" << endl;  if ( errno == EACCES )
                         error( KIO::ERR_WRITE_ACCESS_DENIED, dest );
@@ -605,7 +605,7 @@
                 remove( _dest.data() );
             }
             else {
-                error( KIO::ERR_SLAVE_DEFINED, 
+                error( KIO::ERR_SLAVE_DEFINED,
                         i18n("Cannot copy file from %1 to %2. (Errno: %3)")
                         .arg( src.path() ).arg( dest.path() ).arg( errno ) );
             }
@@ -684,7 +684,7 @@
     QCString _src( QFile::encodeName(src.path()));
     QCString _dest( QFile::encodeName(dest.path()));
     KDE_struct_stat buff_src;
-    if ( KDE_stat( _src.data(), &buff_src ) == -1 ) {
+    if ( KDE_lstat( _src.data(), &buff_src ) == -1 ) {
         if ( errno == EACCES )
            error( KIO::ERR_ACCESS_DENIED, src.path() );
         else
@@ -1091,8 +1091,6 @@
     chdir(path_buffer);
 
     finished();
-
-    kdDebug(7101) << "=============== BYE ===========" << endl;
 }
 
 /*
@@ -1474,14 +1472,14 @@
 bool FileProtocol::pumount(const QString &point)
 {
     QString real_point = KStandardDirs::realPath(point);
-		
+
     KMountPoint::List mtab = KMountPoint::currentMountPoints();
 
     KMountPoint::List::const_iterator it = mtab.begin();
     KMountPoint::List::const_iterator end = mtab.end();
 
     QString dev;
-	
+
     for (; it!=end; ++it)
     {
         QString tmp = (*it)->mountedFrom();


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

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