From d1574fec83fae4979fe31de1de163efb9bc1318a Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Fri, 14 Dec 2007 18:16:25 +0000 Subject: [PATCH] The rename() function removed in rev had in fact move() functionality. So we replace all uses of renameTo() with the new FileName::moveTo() method. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@22149 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/Buffer.cpp | 4 ++-- src/Mover.cpp | 2 +- src/insets/InsetGraphics.cpp | 2 +- src/support/FileName.cpp | 13 +++++++++++++ src/support/FileName.h | 6 ++++++ 5 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/Buffer.cpp b/src/Buffer.cpp index 7c3e85b3bd..7ea74bdb22 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -845,7 +845,7 @@ bool Buffer::save() const } else { // Saving failed, so backup is not backup if (madeBackup) - backupName.renameTo(d->filename); + backupName.moveTo(d->filename); return false; } } @@ -1926,7 +1926,7 @@ int AutoSaveBuffer::generateChild() if (!tmp_ret.empty()) { buffer_.writeFile(tmp_ret); // assume successful write of tmp_ret - if (!tmp_ret.renameTo(fname_)) { + if (!tmp_ret.moveTo(fname_)) { failed = true; // most likely couldn't move between // filesystems unless write of tmp_ret diff --git a/src/Mover.cpp b/src/Mover.cpp index 4837350830..28f2ce950a 100644 --- a/src/Mover.cpp +++ b/src/Mover.cpp @@ -49,7 +49,7 @@ bool Mover::rename(FileName const & from, bool Mover::do_rename(FileName const & from, FileName const & to, string const &) const { - return from.renameTo(to); + return from.moveTo(to); } diff --git a/src/insets/InsetGraphics.cpp b/src/insets/InsetGraphics.cpp index cfb602cb3c..15077095e1 100644 --- a/src/insets/InsetGraphics.cpp +++ b/src/insets/InsetGraphics.cpp @@ -688,7 +688,7 @@ string const InsetGraphics::prepareFile(Buffer const & buf, // the file format from the extension, so we must // change it. FileName const new_file = FileName(changeExtension(temp_file.absFilename(), ext)); - if (temp_file.renameTo(new_file)) { + if (temp_file.moveTo(new_file)) { temp_file = new_file; output_file = changeExtension(output_file, ext); source_file = FileName(changeExtension(source_file.absFilename(), ext)); diff --git a/src/support/FileName.cpp b/src/support/FileName.cpp index 779e4082f0..a596463a88 100644 --- a/src/support/FileName.cpp +++ b/src/support/FileName.cpp @@ -150,6 +150,19 @@ bool FileName::renameTo(FileName const & name) const } +bool FileName::moveTo(FileName const & name) const +{ + if (name.exists() && !name.removeFile()) + return false; + + bool success = QFile::rename(d->fi.absoluteFilePath(), + name.d->fi.absoluteFilePath()); + if (!success) + LYXERR0("Could not move file " << *this << " to " << name); + return success; +} + + bool FileName::changePermission(unsigned long int mode) const { if (!isWritable()) { diff --git a/src/support/FileName.h b/src/support/FileName.h index d338a6a498..16de028ccb 100644 --- a/src/support/FileName.h +++ b/src/support/FileName.h @@ -99,9 +99,15 @@ public: bool removeFile() const; /// rename pointed file. + /// \return false if the operation fails or if the \param target file + /// already exists. /// \return true on success. bool renameTo(FileName const & target) const; + /// move pointed file to \param target. + /// \return true on success. + bool moveTo(FileName const & target) const; + /// change mode of pointed file. /// This methods does nothing and return true on platforms that does not /// support this.