author | ar <ar> | 2004-06-18 19:58:14 (UTC) |
---|---|---|
committer | ar <ar> | 2004-06-18 19:58:14 (UTC) |
commit | d45caef648bce4a73f6f847bc6e9aad125977deb (patch) (unidiff) | |
tree | 2e57aec5300028df4b90b1d07aeabd84e4ebc72f | |
parent | 589dc38a4c44ed7cdd151cf6c136b199ec273398 (diff) | |
download | opie-d45caef648bce4a73f6f847bc6e9aad125977deb.zip opie-d45caef648bce4a73f6f847bc6e9aad125977deb.tar.gz opie-d45caef648bce4a73f6f847bc6e9aad125977deb.tar.bz2 |
- use QFile::encodeName instead of (const char*) or latin1()
- use POSIX rename
-rw-r--r-- | library/filemanager.cpp | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/library/filemanager.cpp b/library/filemanager.cpp index 47af1c6..2e5efdd 100644 --- a/library/filemanager.cpp +++ b/library/filemanager.cpp | |||
@@ -19,24 +19,25 @@ | |||
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #include "filemanager.h" | 21 | #include "filemanager.h" |
22 | #include "applnk.h" | 22 | #include "applnk.h" |
23 | 23 | ||
24 | /* QT */ | 24 | /* QT */ |
25 | #include <qdir.h> | 25 | #include <qdir.h> |
26 | #include <qfileinfo.h> | 26 | #include <qfileinfo.h> |
27 | #include <qtextstream.h> | 27 | #include <qtextstream.h> |
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 | /*! |
34 | \class FileManager | 35 | \class FileManager |
35 | \brief The FileManager class assists with AppLnk input/output. | 36 | \brief The FileManager class assists with AppLnk input/output. |
36 | */ | 37 | */ |
37 | 38 | ||
38 | /*! | 39 | /*! |
39 | Constructs a FileManager. | 40 | Constructs a FileManager. |
40 | */ | 41 | */ |
41 | FileManager::FileManager() | 42 | FileManager::FileManager() |
42 | { | 43 | { |
@@ -179,31 +180,31 @@ bool FileManager::copyFile( const AppLnk &src, const AppLnk &dest ) | |||
179 | 180 | ||
180 | ensurePathExists( fileName ); | 181 | ensurePathExists( fileName ); |
181 | 182 | ||
182 | bool ok = TRUE; | 183 | bool ok = TRUE; |
183 | ok = copyFile( src.file(), fileName ); | 184 | ok = copyFile( src.file(), fileName ); |
184 | 185 | ||
185 | if ( ok ) | 186 | if ( ok ) |
186 | ok = dest.writeLink(); | 187 | ok = dest.writeLink(); |
187 | 188 | ||
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 | } |
201 | 202 | ||
202 | bool FileManager::copyFile( const QString & src, const QString & dest ) | 203 | bool FileManager::copyFile( const QString & src, const QString & dest ) |
203 | { | 204 | { |
204 | //open read file | 205 | //open read file |
205 | QFile srcFile( src ); | 206 | QFile srcFile( src ); |
206 | if( !srcFile.open( IO_ReadOnly|IO_Raw) ) | 207 | if( !srcFile.open( IO_ReadOnly|IO_Raw) ) |
207 | { | 208 | { |
208 | qWarning( "open read failed %s, %s", src.latin1(), dest.latin1() ); | 209 | qWarning( "open read failed %s, %s", src.latin1(), dest.latin1() ); |
209 | return FALSE; | 210 | return FALSE; |
@@ -232,38 +233,37 @@ bool FileManager::copyFile( const QString & src, const QString & dest ) | |||
232 | { | 233 | { |
233 | int bytesWritten = destFile.writeBlock( buffer, bytesRead ); | 234 | int bytesWritten = destFile.writeBlock( buffer, bytesRead ); |
234 | if ( bytesWritten < 0 ) | 235 | if ( bytesWritten < 0 ) |
235 | ok = FALSE; | 236 | ok = FALSE; |
236 | else | 237 | else |
237 | bytesRead -= bytesWritten; | 238 | bytesRead -= bytesWritten; |
238 | } | 239 | } |
239 | } | 240 | } |
240 | srcFile.close(); | 241 | srcFile.close(); |
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 | } |
250 | 251 | ||
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; |
261 | } | 261 | } |
262 | 262 | ||
263 | /*! | 263 | /*! |
264 | Opens the document specified by \a f as a readable QIODevice. | 264 | Opens the document specified by \a f as a readable QIODevice. |
265 | The caller must delete the return value. | 265 | The caller must delete the return value. |
266 | 266 | ||
267 | Returns 0 if the operation fails. | 267 | Returns 0 if the operation fails. |
268 | */ | 268 | */ |
269 | QIODevice* FileManager::openFile( const DocLnk& f ) | 269 | QIODevice* FileManager::openFile( const DocLnk& f ) |
@@ -311,18 +311,17 @@ bool FileManager::exists( const DocLnk &f ) | |||
311 | } | 311 | } |
312 | 312 | ||
313 | /*! | 313 | /*! |
314 | Ensures that the path \a fn exists, by creating required directories. | 314 | Ensures that the path \a fn exists, by creating required directories. |
315 | Returns TRUE if successful. | 315 | Returns TRUE if successful. |
316 | */ | 316 | */ |
317 | bool FileManager::ensurePathExists( const QString &fn ) | 317 | bool FileManager::ensurePathExists( const QString &fn ) |
318 | { | 318 | { |
319 | QFileInfo fi(fn); | 319 | QFileInfo fi(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 | } |