summaryrefslogtreecommitdiff
authorar <ar>2004-06-19 14:27:36 (UTC)
committer ar <ar>2004-06-19 14:27:36 (UTC)
commit8beb35ab232bf3f20582cf6d1d00681b8dd8e24d (patch) (side-by-side diff)
tree4a1eb02423a1053ec9524bb1544893d0686bfbbd
parent0689d1b607583b9b4ebf55b2180bba99d6008d90 (diff)
downloadopie-8beb35ab232bf3f20582cf6d1d00681b8dd8e24d.zip
opie-8beb35ab232bf3f20582cf6d1d00681b8dd8e24d.tar.gz
opie-8beb35ab232bf3f20582cf6d1d00681b8dd8e24d.tar.bz2
- ignore ENOENT and EAGAIN in renameFile (bug in system?)
- replace system-call "mkdir..." with QDir::mkdir
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--library/filemanager.cpp18
1 files changed, 10 insertions, 8 deletions
diff --git a/library/filemanager.cpp b/library/filemanager.cpp
index 2e5efdd..fbfa1d9 100644
--- a/library/filemanager.cpp
+++ b/library/filemanager.cpp
@@ -233,50 +233,53 @@ bool FileManager::copyFile( const QString & src, const QString & dest )
{
int bytesWritten = destFile.writeBlock( buffer, bytesRead );
if ( bytesWritten < 0 )
ok = FALSE;
else
bytesRead -= bytesWritten;
}
}
srcFile.close();
destFile.close();
// Set file permissions
struct stat status;
if( stat( QFile::encodeName( src ), &status ) == 0 )
{
chmod( QFile::encodeName( dest ), status.st_mode );
}
return ok;
}
bool FileManager::renameFile( const QString & src, const QString & dest )
{
if( rename( QFile::encodeName( src ), QFile::encodeName( dest ) ) == -1);
{
- qWarning( "problem renaming file %s to %s, errno: %d", src.latin1(), dest.latin1(), errno );
- return false;
+ if ( errno != 2 && errno != 11 ) //ignore ENOENT and EAGAIN - bug in system?
+ {
+ qWarning( "problem renaming file %s to %s, errno: %d", src.latin1(), dest.latin1(), errno );
+ return false;
+ }
}
return true;
}
/*!
Opens the document specified by \a f as a readable QIODevice.
The caller must delete the return value.
Returns 0 if the operation fails.
*/
QIODevice* FileManager::openFile( const DocLnk& f )
{
QString fn = f.file();
QFile* fl = new QFile( fn );
if ( !fl->open( IO_ReadOnly ) )
{
delete fl;
fl = 0;
}
return fl;
}
/*!
Opens the document specified by \a f as a writable QIODevice.
@@ -290,38 +293,37 @@ QIODevice* FileManager::saveFile( const DocLnk& f )
ensurePathExists( fn );
QFile* fl = new QFile( fn );
if ( fl->open( IO_WriteOnly ) )
{
f.writeLink();
}
else
{
delete fl;
fl = 0;
}
return fl;
}
/*!
Returns whether the document specified by \a f current exists
as a file on disk.
*/
bool FileManager::exists( const DocLnk &f )
{
return QFile::exists(f.file());
}
/*!
- Ensures that the path \a fn exists, by creating required directories.
+ Ensures that the path \a fileName exists, by creating required directories.
Returns TRUE if successful.
*/
-bool FileManager::ensurePathExists( const QString &fn )
+bool FileManager::ensurePathExists( const QString &fileName )
{
- QFileInfo fi(fn);
- fi.setFile( fi.dirPath(TRUE) );
- if ( !fi.exists() )
+ QDir directory = QFileInfo( fileName ).dir();
+ if ( !directory.exists() )
{
- if ( system( ("mkdir -p " + QFile::encodeName( fi.filePath() ) ) ) )
+ if ( !directory.mkdir( directory.absPath() ) )
return FALSE;
}
return TRUE;
}