summaryrefslogtreecommitdiff
path: root/library/filemanager.cpp
authorar <ar>2004-06-19 14:27:36 (UTC)
committer ar <ar>2004-06-19 14:27:36 (UTC)
commit8beb35ab232bf3f20582cf6d1d00681b8dd8e24d (patch) (unidiff)
tree4a1eb02423a1053ec9524bb1544893d0686bfbbd /library/filemanager.cpp
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 (limited to 'library/filemanager.cpp') (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 )
233 { 233 {
234 int bytesWritten = destFile.writeBlock( buffer, bytesRead ); 234 int bytesWritten = destFile.writeBlock( buffer, bytesRead );
235 if ( bytesWritten < 0 ) 235 if ( bytesWritten < 0 )
236 ok = FALSE; 236 ok = FALSE;
237 else 237 else
238 bytesRead -= bytesWritten; 238 bytesRead -= bytesWritten;
239 } 239 }
240 } 240 }
241 srcFile.close(); 241 srcFile.close();
242 destFile.close(); 242 destFile.close();
243 // Set file permissions 243 // Set file permissions
244 struct stat status; 244 struct stat status;
245 if( stat( QFile::encodeName( src ), &status ) == 0 ) 245 if( stat( QFile::encodeName( src ), &status ) == 0 )
246 { 246 {
247 chmod( QFile::encodeName( dest ), status.st_mode ); 247 chmod( QFile::encodeName( dest ), status.st_mode );
248 } 248 }
249 return ok; 249 return ok;
250} 250}
251 251
252 252
253bool FileManager::renameFile( const QString & src, const QString & dest ) 253bool FileManager::renameFile( const QString & src, const QString & dest )
254{ 254{
255 if( rename( QFile::encodeName( src ), QFile::encodeName( dest ) ) == -1); 255 if( rename( QFile::encodeName( src ), QFile::encodeName( dest ) ) == -1);
256 { 256 {
257 qWarning( "problem renaming file %s to %s, errno: %d", src.latin1(), dest.latin1(), errno ); 257 if ( errno != 2 && errno != 11 ) //ignore ENOENT and EAGAIN - bug in system?
258 return false; 258 {
259 qWarning( "problem renaming file %s to %s, errno: %d", src.latin1(), dest.latin1(), errno );
260 return false;
261 }
259 } 262 }
260 return true; 263 return true;
261} 264}
262 265
263/*! 266/*!
264 Opens the document specified by \a f as a readable QIODevice. 267 Opens the document specified by \a f as a readable QIODevice.
265 The caller must delete the return value. 268 The caller must delete the return value.
266 269
267 Returns 0 if the operation fails. 270 Returns 0 if the operation fails.
268*/ 271*/
269QIODevice* FileManager::openFile( const DocLnk& f ) 272QIODevice* FileManager::openFile( const DocLnk& f )
270{ 273{
271 QString fn = f.file(); 274 QString fn = f.file();
272 QFile* fl = new QFile( fn ); 275 QFile* fl = new QFile( fn );
273 if ( !fl->open( IO_ReadOnly ) ) 276 if ( !fl->open( IO_ReadOnly ) )
274 { 277 {
275 delete fl; 278 delete fl;
276 fl = 0; 279 fl = 0;
277 } 280 }
278 return fl; 281 return fl;
279} 282}
280 283
281/*! 284/*!
282 Opens the document specified by \a f as a writable QIODevice. 285 Opens the document specified by \a f as a writable QIODevice.
@@ -290,38 +293,37 @@ QIODevice* FileManager::saveFile( const DocLnk& f )
290 ensurePathExists( fn ); 293 ensurePathExists( fn );
291 QFile* fl = new QFile( fn ); 294 QFile* fl = new QFile( fn );
292 if ( fl->open( IO_WriteOnly ) ) 295 if ( fl->open( IO_WriteOnly ) )
293 { 296 {
294 f.writeLink(); 297 f.writeLink();
295 } 298 }
296 else 299 else
297 { 300 {
298 delete fl; 301 delete fl;
299 fl = 0; 302 fl = 0;
300 } 303 }
301 return fl; 304 return fl;
302} 305}
303 306
304/*! 307/*!
305 Returns whether the document specified by \a f current exists 308 Returns whether the document specified by \a f current exists
306 as a file on disk. 309 as a file on disk.
307*/ 310*/
308bool FileManager::exists( const DocLnk &f ) 311bool FileManager::exists( const DocLnk &f )
309{ 312{
310 return QFile::exists(f.file()); 313 return QFile::exists(f.file());
311} 314}
312 315
313/*! 316/*!
314 Ensures that the path \a fn exists, by creating required directories. 317 Ensures that the path \a fileName exists, by creating required directories.
315 Returns TRUE if successful. 318 Returns TRUE if successful.
316*/ 319*/
317bool FileManager::ensurePathExists( const QString &fn ) 320bool FileManager::ensurePathExists( const QString &fileName )
318{ 321{
319 QFileInfo fi(fn); 322 QDir directory = QFileInfo( fileName ).dir();
320 fi.setFile( fi.dirPath(TRUE) ); 323 if ( !directory.exists() )
321 if ( !fi.exists() )
322 { 324 {
323 if ( system( ("mkdir -p " + QFile::encodeName( fi.filePath() ) ) ) ) 325 if ( !directory.mkdir( directory.absPath() ) )
324 return FALSE; 326 return FALSE;
325 } 327 }
326 return TRUE; 328 return TRUE;
327} 329}