On Fri, Dec 14, 2007 at 11:17:35PM +0100, Abdelrazak Younes wrote: > Enrico Forestieri wrote: > > On Fri, Dec 14, 2007 at 06:16:28PM -0000, [EMAIL PROTECTED] wrote: > > > >> Author: younes > >> Date: Fri Dec 14 19:16:25 2007 > >> New Revision: 22149 > >> > >> URL: http://www.lyx.org/trac/changeset/22149 > >> Log: > >> The rename() function removed in rev had in fact move() functionality. So > >> we replace all uses of renameTo() with the new FileName::moveTo() method. > >> > >> Modified: > >> lyx-devel/trunk/src/Buffer.cpp > >> lyx-devel/trunk/src/Mover.cpp > >> lyx-devel/trunk/src/insets/InsetGraphics.cpp > >> lyx-devel/trunk/src/support/FileName.cpp > >> lyx-devel/trunk/src/support/FileName.h > > ... > >> Modified: lyx-devel/trunk/src/support/FileName.cpp > >> URL: > >> http://www.lyx.org/trac/file/lyx-devel/trunk/src/support/FileName.cpp?rev=22149 > >> ============================================================================== > >> --- lyx-devel/trunk/src/support/FileName.cpp (original) > >> +++ lyx-devel/trunk/src/support/FileName.cpp Fri Dec 14 19:16:25 2007 > >> @@ -146,6 +146,19 @@ > >> bool success = QFile::rename(d->fi.absoluteFilePath(), > >> name.d->fi.absoluteFilePath()); > >> if (!success) > >> LYXERR0("Could not rename file " << *this << " to " << name); > >> + return success; > >> +} > >> + > >> + > >> +bool FileName::moveTo(FileName const & name) const > >> +{ > >> + if (name.exists() && !name.removeFile()) > >> + return false; > > > > This is wrong. Simply try to remove the file without checking for its > > existence and then fall through to directly trying to rename. In case > > the file the could not be removed, the rename fails and you get the > > warning. Otherwise, sometimes you are warned and sometimes not. > > Well, I don't want a warning if the file does not exist. If it exists > and its removal fails I will get the true warning from > FileName::removeFile().
And this is wrong because you should get the warning about the impossibility to move the file, not to delete the destination. > If I do like you advice I will get two warning. You do not when using the attached patch. > But I see that the check for existence is already there in > FileName::removeFile() (you introduced it right?). Wrong, you did. I simply introduced the existence check because I find stupid being warned about the impossibility to remove a non-existent file. > Trying to remove a > file that does not exist seems like a waste of time to me. Not more than checking for its existence. What do you think it is done when you try to remove a file? ;-) -- Enrico
Index: src/support/FileName.cpp =================================================================== --- src/support/FileName.cpp (revision 22151) +++ src/support/FileName.cpp (working copy) @@ -152,8 +152,7 @@ bool FileName::renameTo(FileName const & bool FileName::moveTo(FileName const & name) const { - if (name.exists() && !name.removeFile()) - return false; + QFile::remove(name.d->fi.absoluteFilePath()); bool success = QFile::rename(d->fi.absoluteFilePath(), name.d->fi.absoluteFilePath());