-rw-r--r-- | library/filemanager.cpp | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/library/filemanager.cpp b/library/filemanager.cpp index 47af1c6..2e5efdd 100644 --- a/library/filemanager.cpp +++ b/library/filemanager.cpp | |||
@@ -28,6 +28,7 @@ | |||
28 | 28 | ||
29 | /* STD */ | 29 | /* STD */ |
30 | #include <stdlib.h> | 30 | #include <stdlib.h> |
31 | #include <errno.h> | ||
31 | #include <sys/stat.h> | 32 | #include <sys/stat.h> |
32 | 33 | ||
33 | /*! | 34 | /*! |
@@ -63,18 +64,18 @@ bool FileManager::saveFile( const DocLnk &f, const QByteArray &data ) | |||
63 | //write data in temporary .new file | 64 | //write data in temporary .new file |
64 | if ( !file.open( IO_WriteOnly|IO_Raw ) ) | 65 | if ( !file.open( IO_WriteOnly|IO_Raw ) ) |
65 | { | 66 | { |
66 | qWarning("open failed"); | 67 | qWarning( "open failed" ); |
67 | return FALSE; | 68 | return FALSE; |
68 | } | 69 | } |
69 | int total_written = file.writeBlock( data ); | 70 | int total_written = file.writeBlock( data ); |
70 | file.close(); | 71 | file.close(); |
71 | //check if every was written | 72 | //check if every was written |
72 | if ( total_written != int(data.size()) || !f.writeLink() ) | 73 | if ( total_written != int( data.size() ) || !f.writeLink() ) |
73 | { | 74 | { |
74 | QFile::remove( fileName ); | 75 | QFile::remove( fileName ); |
75 | return FALSE; | 76 | return FALSE; |
76 | } | 77 | } |
77 | qDebug("total written %d out of %d", total_written, data.size()); | 78 | qDebug( "total written %d out of %d", total_written, data.size() ); |
78 | 79 | ||
79 | //rename temporary .new file in original filenam | 80 | //rename temporary .new file in original filenam |
80 | if ( !renameFile( fileName, f.file() ) ) | 81 | if ( !renameFile( fileName, f.file() ) ) |
@@ -98,7 +99,7 @@ bool FileManager::saveFile( const DocLnk &f, const QString &text ) | |||
98 | //write data in temporary .new file | 99 | //write data in temporary .new file |
99 | if ( !file.open( IO_WriteOnly|IO_Raw ) ) | 100 | if ( !file.open( IO_WriteOnly|IO_Raw ) ) |
100 | { | 101 | { |
101 | qWarning("open failed"); | 102 | qWarning( "open failed" ); |
102 | return FALSE; | 103 | return FALSE; |
103 | } | 104 | } |
104 | 105 | ||
@@ -106,7 +107,7 @@ bool FileManager::saveFile( const DocLnk &f, const QString &text ) | |||
106 | int total_written; | 107 | int total_written; |
107 | total_written = file.writeBlock( cstr.data(), cstr.length() ); | 108 | total_written = file.writeBlock( cstr.data(), cstr.length() ); |
108 | file.close(); | 109 | file.close(); |
109 | if ( total_written != int(cstr.length()) || !f.writeLink() ) | 110 | if ( total_written != int( cstr.length()) || !f.writeLink() ) |
110 | { | 111 | { |
111 | QFile::remove( fileName ); | 112 | QFile::remove( fileName ); |
112 | return FALSE; | 113 | return FALSE; |
@@ -188,13 +189,13 @@ bool FileManager::copyFile( const AppLnk &src, const AppLnk &dest ) | |||
188 | if ( ok ) | 189 | if ( ok ) |
189 | { | 190 | { |
190 | // okay now rename the file... | 191 | // okay now rename the file... |
191 | if ( !renameFile( fileName.latin1(), dest.file().latin1() ) ) | 192 | if ( !renameFile( fileName, dest.file() ) ) |
192 | // remove the tmp file, otherwise, it will just lay around... | 193 | // remove the tmp file, otherwise, it will just lay around... |
193 | QFile::remove( fileName.latin1() ); | 194 | QFile::remove( fileName ); |
194 | } | 195 | } |
195 | else | 196 | else |
196 | { | 197 | { |
197 | QFile::remove( fileName.latin1() ); | 198 | QFile::remove( fileName ); |
198 | } | 199 | } |
199 | return ok; | 200 | return ok; |
200 | } | 201 | } |
@@ -241,9 +242,9 @@ bool FileManager::copyFile( const QString & src, const QString & dest ) | |||
241 | destFile.close(); | 242 | destFile.close(); |
242 | // Set file permissions | 243 | // Set file permissions |
243 | struct stat status; | 244 | struct stat status; |
244 | if( stat( (const char *) src, &status ) == 0 ) | 245 | if( stat( QFile::encodeName( src ), &status ) == 0 ) |
245 | { | 246 | { |
246 | chmod( (const char *) dest, status.st_mode ); | 247 | chmod( QFile::encodeName( dest ), status.st_mode ); |
247 | } | 248 | } |
248 | return ok; | 249 | return ok; |
249 | } | 250 | } |
@@ -251,10 +252,9 @@ bool FileManager::copyFile( const QString & src, const QString & dest ) | |||
251 | 252 | ||
252 | bool FileManager::renameFile( const QString & src, const QString & dest ) | 253 | bool FileManager::renameFile( const QString & src, const QString & dest ) |
253 | { | 254 | { |
254 | QDir dir( QFileInfo( src ).absFilePath() ); | 255 | if( rename( QFile::encodeName( src ), QFile::encodeName( dest ) ) == -1); |
255 | if ( !dir.rename( src, dest ) ) | ||
256 | { | 256 | { |
257 | qWarning( "problem renaming file %s to %s", src, dest ); | 257 | qWarning( "problem renaming file %s to %s, errno: %d", src.latin1(), dest.latin1(), errno ); |
258 | return false; | 258 | return false; |
259 | } | 259 | } |
260 | return true; | 260 | return true; |
@@ -320,9 +320,8 @@ bool FileManager::ensurePathExists( const QString &fn ) | |||
320 | fi.setFile( fi.dirPath(TRUE) ); | 320 | fi.setFile( fi.dirPath(TRUE) ); |
321 | if ( !fi.exists() ) | 321 | if ( !fi.exists() ) |
322 | { | 322 | { |
323 | if ( system(("mkdir -p "+fi.filePath())) ) | 323 | if ( system( ("mkdir -p " + QFile::encodeName( fi.filePath() ) ) ) ) |
324 | return FALSE; | 324 | return FALSE; |
325 | } | 325 | } |
326 | |||
327 | return TRUE; | 326 | return TRUE; |
328 | } | 327 | } |