summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--library/filemanager.cpp6
1 files changed, 3 insertions, 3 deletions
diff --git a/library/filemanager.cpp b/library/filemanager.cpp
index eff8429..408be20 100644
--- a/library/filemanager.cpp
+++ b/library/filemanager.cpp
@@ -187,154 +187,154 @@ bool FileManager::copyFile( const AppLnk &src, const AppLnk &dest )
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
228bool FileManager::copyFile( const QString & src, const QString & dest ) { 228bool FileManager::copyFile( const QString & src, const QString & dest ) {
229 bool success = true; 229 bool success = true;
230 struct stat status; 230 struct stat status;
231 int read_fd=0; 231 int read_fd=0;
232 int write_fd=0; 232 int write_fd=0;
233 struct stat stat_buf; 233 struct stat stat_buf;
234 off_t offset = 0; 234 off_t offset = 0;
235 QFile srcFile(src); 235 QFile srcFile(src);
236 QFile destFile(dest); 236 QFile destFile(dest);
237 237
238 if(!srcFile.open( IO_ReadOnly|IO_Raw)) { 238 if(!srcFile.open( IO_ReadOnly|IO_Raw)) {
239 return success = false; 239 return success = false;
240 } 240 }
241 read_fd = srcFile.handle(); 241 read_fd = srcFile.handle();
242 if(read_fd != -1) { 242 if(read_fd != -1) {
243 fstat (read_fd, &stat_buf); 243 fstat (read_fd, &stat_buf);
244 if( !destFile.open( IO_WriteOnly|IO_Raw ) ) 244 if( !destFile.open( IO_WriteOnly|IO_Raw ) )
245 return success = false; 245 return success = false;
246 write_fd = destFile.handle(); 246 write_fd = destFile.handle();
247 if(write_fd != -1) { 247 if(write_fd != -1) {
248 int err=0; 248 int err=0;
249 QString msg; 249 QString msg;
250#ifdef Q_OS_MACX 250#ifdef Q_OS_MACX
251#ifdef SENDMAIL 251#ifdef SENDFILE
252 /* FreeBSD does support a different kind of 252 /* FreeBSD does support a different kind of
253 * sendfile. (eilers) 253 * sendfile. (eilers)
254 * I took this from Very Secure FTPd 254 * I took this from Very Secure FTPd
255 * Licence: GPL 255 * Licence: GPL
256 * Author: Chris Evans 256 * Author: Chris Evans
257 * sysdeputil.c 257 * sysdeputil.c
258 */ 258 */
259 /* XXX - start_pos will truncate on 32-bit machines - can we 259 /* XXX - start_pos will truncate on 32-bit machines - can we
260 * say "start from current pos"? 260 * say "start from current pos"?
261 */ 261 */
262 off_t written = 0; 262 off_t written = 0;
263 int retval = 0; 263 int retval = 0;
264 retval = sendfile(read_fd, write_fd, offset, stat_buf.st_size, NULL, 264 retval = sendfile(read_fd, write_fd, offset, stat_buf.st_size, NULL,
265 &written, 0); 265 &written, 0);
266 /* Translate to Linux-like retval */ 266 /* Translate to Linux-like retval */
267 if (written > 0) 267 if (written > 0)
268 { 268 {
269 err = (int) written; 269 err = (int) written;
270 } 270 }
271#else /* SENDMAIL */ 271#else /* SENDFILE */
272 err == -1; 272 err == -1;
273 msg = "FAILURE: Using unsupported function \"sendfile()\" Need Workaround !!"; 273 msg = "FAILURE: Using unsupported function \"sendfile()\" Need Workaround !!";
274 success = false; 274 success = false;
275# warning "Need workaround for sendfile!!(eilers)" 275# warning "Need workaround for sendfile!!(eilers)"
276#endif /* SENDMAIL */ 276#endif /* SENDFILE */
277 277
278#else 278#else
279 err = sendfile(write_fd, read_fd, &offset, stat_buf.st_size); 279 err = sendfile(write_fd, read_fd, &offset, stat_buf.st_size);
280 if( err == -1) { 280 if( err == -1) {
281 switch(err) { 281 switch(err) {
282 case EBADF : msg = "The input file was not opened for reading or the output file was not opened for writing. "; 282 case EBADF : msg = "The input file was not opened for reading or the output file was not opened for writing. ";
283 case EINVAL: msg = "Descriptor is not valid or locked. "; 283 case EINVAL: msg = "Descriptor is not valid or locked. ";
284 case ENOMEM: msg = "Insufficient memory to read from in_fd."; 284 case ENOMEM: msg = "Insufficient memory to read from in_fd.";
285 case EIO: msg = "Unspecified error while reading from in_fd."; 285 case EIO: msg = "Unspecified error while reading from in_fd.";
286 }; 286 };
287 success = false; 287 success = false;
288 } 288 }
289#endif /* Q_OS_MACX */ 289#endif /* Q_OS_MACX */
290 if( !success ) 290 if( !success )
291 qWarning( msg ); 291 qWarning( msg );
292 } else { 292 } else {
293 qWarning("open write failed %s, %s",src.latin1(), dest.latin1()); 293 qWarning("open write failed %s, %s",src.latin1(), dest.latin1());
294 success = false; 294 success = false;
295 } 295 }
296 } else { 296 } else {
297 qWarning("open read failed %s, %s",src.latin1(), dest.latin1()); 297 qWarning("open read failed %s, %s",src.latin1(), dest.latin1());
298 success = false; 298 success = false;
299 } 299 }
300 srcFile.close(); 300 srcFile.close();
301 destFile.close(); 301 destFile.close();
302 // Set file permissions 302 // Set file permissions
303 if( stat( (const char *) src, &status ) == 0 ) { 303 if( stat( (const char *) src, &status ) == 0 ) {
304 chmod( (const char *) dest, status.st_mode ); 304 chmod( (const char *) dest, status.st_mode );
305 } 305 }
306 306
307 return success; 307 return success;
308} 308}
309 309
310 310
311bool FileManager::renameFile( const QString & src, const QString & dest ) { 311bool FileManager::renameFile( const QString & src, const QString & dest ) {
312 if(copyFile( src, dest )) { 312 if(copyFile( src, dest )) {
313 if(QFile::remove(src) ) { 313 if(QFile::remove(src) ) {
314 return true; 314 return true;
315 } 315 }
316 } 316 }
317 return false; 317 return false;
318} 318}
319 319
320/* 320/*
321bool FileManager::copyFile( const QString & src, const QString & dest ) { 321bool FileManager::copyFile( const QString & src, const QString & dest ) {
322 bool success = true; 322 bool success = true;
323 struct stat status; 323 struct stat status;
324 int read_fd=0; 324 int read_fd=0;
325 int write_fd=0; 325 int write_fd=0;
326 struct stat stat_buf; 326 struct stat stat_buf;
327 off_t offset = 0; 327 off_t offset = 0;
328 QFile srcFile(src); 328 QFile srcFile(src);
329 QFile destFile(dest); 329 QFile destFile(dest);
330 330
331 if(!srcFile.open( IO_ReadOnly|IO_Raw)) { 331 if(!srcFile.open( IO_ReadOnly|IO_Raw)) {
332 return success = false; 332 return success = false;
333 } 333 }
334 read_fd = srcFile.handle(); 334 read_fd = srcFile.handle();
335 if(read_fd != -1) { 335 if(read_fd != -1) {
336 fstat (read_fd, &stat_buf); 336 fstat (read_fd, &stat_buf);
337 if( !destFile.open( IO_WriteOnly|IO_Raw ) ) 337 if( !destFile.open( IO_WriteOnly|IO_Raw ) )
338 return success = false; 338 return success = false;
339 write_fd = destFile.handle(); 339 write_fd = destFile.handle();
340 if(write_fd != -1) { 340 if(write_fd != -1) {