author | waspe <waspe> | 2003-11-04 17:08:12 (UTC) |
---|---|---|
committer | waspe <waspe> | 2003-11-04 17:08:12 (UTC) |
commit | dc96afa26288897a9d25ab8c321d8ad350c53f44 (patch) (unidiff) | |
tree | 62678d196ae984d246260279c16e49c2923d7a30 /library | |
parent | 5865ec3970cead5b2cf3dd255a55cf2e1869e330 (diff) | |
download | opie-dc96afa26288897a9d25ab8c321d8ad350c53f44.zip opie-dc96afa26288897a9d25ab8c321d8ad350c53f44.tar.gz opie-dc96afa26288897a9d25ab8c321d8ad350c53f44.tar.bz2 |
resolved merge conflict
-rw-r--r-- | library/filemanager.cpp | 66 |
1 files changed, 63 insertions, 3 deletions
diff --git a/library/filemanager.cpp b/library/filemanager.cpp index 91986a0..1c1c998 100644 --- a/library/filemanager.cpp +++ b/library/filemanager.cpp | |||
@@ -185,69 +185,67 @@ bool FileManager::copyFile( const AppLnk &src, const AppLnk &dest ) | |||
185 | return FALSE; | 185 | return FALSE; |
186 | 186 | ||
187 | QString fn = dest.file() + ".new"; | 187 | QString fn = dest.file() + ".new"; |
188 | ensurePathExists( fn ); | 188 | ensurePathExists( fn ); |
189 | QFile df( fn ); | 189 | QFile df( fn ); |
190 | if ( !df.open( IO_WriteOnly|IO_Raw ) ) | 190 | if ( !df.open( IO_WriteOnly|IO_Raw ) ) |
191 | return FALSE; | 191 | return FALSE; |
192 | 192 | ||
193 | const int bufsize = 16384; | 193 | const int bufsize = 16384; |
194 | char buffer[bufsize]; | 194 | char buffer[bufsize]; |
195 | bool ok = TRUE; | 195 | bool ok = TRUE; |
196 | int bytesRead = 0; | 196 | int bytesRead = 0; |
197 | while ( ok && !sf.atEnd() ) { | 197 | while ( ok && !sf.atEnd() ) { |
198 | bytesRead = sf.readBlock( buffer, bufsize ); | 198 | bytesRead = sf.readBlock( buffer, bufsize ); |
199 | if ( bytesRead < 0 ) | 199 | if ( bytesRead < 0 ) |
200 | ok = FALSE; | 200 | ok = FALSE; |
201 | while ( ok && bytesRead > 0 ) { | 201 | while ( ok && bytesRead > 0 ) { |
202 | int bytesWritten = df.writeBlock( buffer, bytesRead ); | 202 | int bytesWritten = df.writeBlock( buffer, bytesRead ); |
203 | if ( bytesWritten < 0 ) | 203 | if ( bytesWritten < 0 ) |
204 | ok = FALSE; | 204 | ok = FALSE; |
205 | else | 205 | else |
206 | bytesRead -= bytesWritten; | 206 | bytesRead -= bytesWritten; |
207 | } | 207 | } |
208 | } | 208 | } |
209 | 209 | ||
210 | if ( ok ) | 210 | if ( ok ) |
211 | ok = dest.writeLink(); | 211 | ok = dest.writeLink(); |
212 | 212 | ||
213 | if ( ok ) { | 213 | if ( ok ) { |
214 | // okay now rename the file... | 214 | // okay now rename the file... |
215 | if ( !renameFile( fn.latin1(), dest.file().latin1() ) ) { | 215 | if ( !renameFile( fn.latin1(), dest.file().latin1() ) ) { |
216 | qWarning( "problem renaming file %s to %s, errno: %d", fn.latin1(), | 216 | qWarning( "problem renaming file %s to %s, errno: %d", fn.latin1(), |
217 | dest.file().latin1(), errno ); | 217 | dest.file().latin1(), errno ); |
218 | // remove the tmp file, otherwise, it will just lay around... | 218 | // remove the tmp file, otherwise, it will just lay around... |
219 | QFile::remove( fn.latin1() ); | 219 | QFile::remove( fn.latin1() ); |
220 | } | 220 | } |
221 | } else { | 221 | } else { |
222 | QFile::remove( fn.latin1() ); | 222 | QFile::remove( fn.latin1() ); |
223 | } | 223 | } |
224 | 224 | ||
225 | return ok; | 225 | return ok; |
226 | } | 226 | } |
227 | 227 | ||
228 | |||
229 | |||
230 | bool FileManager::copyFile( const QString & src, const QString & dest ) { | 228 | bool FileManager::copyFile( const QString & src, const QString & dest ) { |
231 | bool success = true; | 229 | bool success = true; |
232 | struct stat status; | 230 | struct stat status; |
233 | int read_fd=0; | 231 | int read_fd=0; |
234 | int write_fd=0; | 232 | int write_fd=0; |
235 | struct stat stat_buf; | 233 | struct stat stat_buf; |
236 | off_t offset = 0; | 234 | off_t offset = 0; |
237 | QFile srcFile(src); | 235 | QFile srcFile(src); |
238 | QFile destFile(dest); | 236 | QFile destFile(dest); |
239 | 237 | ||
240 | if(!srcFile.open( IO_ReadOnly|IO_Raw)) { | 238 | if(!srcFile.open( IO_ReadOnly|IO_Raw)) { |
241 | return success = false; | 239 | return success = false; |
242 | } | 240 | } |
243 | read_fd = srcFile.handle(); | 241 | read_fd = srcFile.handle(); |
244 | if(read_fd != -1) { | 242 | if(read_fd != -1) { |
245 | fstat (read_fd, &stat_buf); | 243 | fstat (read_fd, &stat_buf); |
246 | if( !destFile.open( IO_WriteOnly|IO_Raw ) ) | 244 | if( !destFile.open( IO_WriteOnly|IO_Raw ) ) |
247 | return success = false; | 245 | return success = false; |
248 | write_fd = destFile.handle(); | 246 | write_fd = destFile.handle(); |
249 | if(write_fd != -1) { | 247 | if(write_fd != -1) { |
250 | int err=0; | 248 | int err=0; |
251 | QString msg; | 249 | QString msg; |
252 | #ifdef Q_OS_MACX | 250 | #ifdef Q_OS_MACX |
253 | #ifdef SENDMAIL | 251 | #ifdef SENDMAIL |
@@ -299,48 +297,110 @@ bool FileManager::copyFile( const QString & src, const QString & dest ) { | |||
299 | qWarning("open read failed %s, %s",src.latin1(), dest.latin1()); | 297 | qWarning("open read failed %s, %s",src.latin1(), dest.latin1()); |
300 | success = false; | 298 | success = false; |
301 | } | 299 | } |
302 | srcFile.close(); | 300 | srcFile.close(); |
303 | destFile.close(); | 301 | destFile.close(); |
304 | // Set file permissions | 302 | // Set file permissions |
305 | if( stat( (const char *) src, &status ) == 0 ) { | 303 | if( stat( (const char *) src, &status ) == 0 ) { |
306 | chmod( (const char *) dest, status.st_mode ); | 304 | chmod( (const char *) dest, status.st_mode ); |
307 | } | 305 | } |
308 | 306 | ||
309 | return success; | 307 | return success; |
310 | } | 308 | } |
311 | 309 | ||
312 | 310 | ||
313 | bool FileManager::renameFile( const QString & src, const QString & dest ) { | 311 | bool FileManager::renameFile( const QString & src, const QString & dest ) { |
314 | if(copyFile( src, dest )) { | 312 | if(copyFile( src, dest )) { |
315 | if(QFile::remove(src) ) { | 313 | if(QFile::remove(src) ) { |
316 | return true; | 314 | return true; |
317 | } | 315 | } |
318 | } | 316 | } |
319 | return false; | 317 | return false; |
320 | } | 318 | } |
321 | 319 | ||
322 | 320 | ||
321 | ======= | ||
322 | bool FileManager::copyFile( const QString & src, const QString & dest ) { | ||
323 | bool success = true; | ||
324 | struct stat status; | ||
325 | int read_fd=0; | ||
326 | int write_fd=0; | ||
327 | struct stat stat_buf; | ||
328 | off_t offset = 0; | ||
329 | QFile srcFile(src); | ||
330 | QFile destFile(dest); | ||
331 | |||
332 | if(!srcFile.open( IO_ReadOnly|IO_Raw)) { | ||
333 | return success = false; | ||
334 | } | ||
335 | read_fd = srcFile.handle(); | ||
336 | if(read_fd != -1) { | ||
337 | fstat (read_fd, &stat_buf); | ||
338 | if( !destFile.open( IO_WriteOnly|IO_Raw ) ) | ||
339 | return success = false; | ||
340 | write_fd = destFile.handle(); | ||
341 | if(write_fd != -1) { | ||
342 | int err=0; | ||
343 | QString msg; | ||
344 | err = sendfile(write_fd, read_fd, &offset, stat_buf.st_size); | ||
345 | if( err == -1) { | ||
346 | switch(err) { | ||
347 | case EBADF : msg = "The input file was not opened for reading or the output file was not opened for writing. "; | ||
348 | case EINVAL: msg = "Descriptor is not valid or locked. "; | ||
349 | case ENOMEM: msg = "Insufficient memory to read from in_fd."; | ||
350 | case EIO: msg = "Unspecified error while reading from in_fd."; | ||
351 | }; | ||
352 | success = false; | ||
353 | } | ||
354 | } else { | ||
355 | qWarning("open write failed %s, %s",src.latin1(), dest.latin1()); | ||
356 | success = false; | ||
357 | } | ||
358 | } else { | ||
359 | qWarning("open read failed %s, %s",src.latin1(), dest.latin1()); | ||
360 | success = false; | ||
361 | } | ||
362 | srcFile.close(); | ||
363 | destFile.close(); | ||
364 | // Set file permissions | ||
365 | if( stat( (const char *) src, &status ) == 0 ) { | ||
366 | chmod( (const char *) dest, status.st_mode ); | ||
367 | } | ||
368 | |||
369 | return success; | ||
370 | } | ||
371 | |||
372 | |||
373 | bool FileManager::renameFile( const QString & src, const QString & dest ) { | ||
374 | if(copyFile( src, dest )) { | ||
375 | if(QFile::remove(src) ) { | ||
376 | return true; | ||
377 | } | ||
378 | } | ||
379 | return false; | ||
380 | } | ||
381 | |||
382 | |||
323 | /*! | 383 | /*! |
324 | Opens the document specified by \a f as a readable QIODevice. | 384 | Opens the document specified by \a f as a readable QIODevice. |
325 | The caller must delete the return value. | 385 | The caller must delete the return value. |
326 | 386 | ||
327 | Returns 0 if the operation fails. | 387 | Returns 0 if the operation fails. |
328 | */ | 388 | */ |
329 | QIODevice* FileManager::openFile( const DocLnk& f ) | 389 | QIODevice* FileManager::openFile( const DocLnk& f ) |
330 | { | 390 | { |
331 | QString fn = f.file(); | 391 | QString fn = f.file(); |
332 | QFile* fl = new QFile( fn ); | 392 | QFile* fl = new QFile( fn ); |
333 | if ( !fl->open( IO_ReadOnly ) ) { | 393 | if ( !fl->open( IO_ReadOnly ) ) { |
334 | delete fl; | 394 | delete fl; |
335 | fl = 0; | 395 | fl = 0; |
336 | } | 396 | } |
337 | return fl; | 397 | return fl; |
338 | } | 398 | } |
339 | 399 | ||
340 | /*! | 400 | /*! |
341 | Opens the document specified by \a f as a writable QIODevice. | 401 | Opens the document specified by \a f as a writable QIODevice. |
342 | The caller must delete the return value. | 402 | The caller must delete the return value. |
343 | 403 | ||
344 | Returns 0 if the operation fails. | 404 | Returns 0 if the operation fails. |
345 | */ | 405 | */ |
346 | QIODevice* FileManager::saveFile( const DocLnk& f ) | 406 | QIODevice* FileManager::saveFile( const DocLnk& f ) |