]> git.lyx.org Git - lyx.git/blobdiff - src/support/FileName.cpp
Revert unintentional commits.
[lyx.git] / src / support / FileName.cpp
index 5e4ea0ec2ecc4d80df724d53d1047bb283aac80f..a2140525893eb149614042e4101eaafe83a797a8 100644 (file)
@@ -28,7 +28,7 @@
 #include <QList>
 #include <QTime>
 
-#include <boost/assert.hpp>
+#include "support/lassert.h"
 #include <boost/scoped_array.hpp>
 
 #include <map>
@@ -140,6 +140,12 @@ bool FileName::empty() const
 }
 
 
+bool FileName::isAbsolute() const
+{
+       return d->fi.isAbsolute();
+}
+
+
 string FileName::absFilename() const
 {
        return fromqstr(d->fi.absoluteFilePath());
@@ -149,7 +155,6 @@ string FileName::absFilename() const
 void FileName::set(string const & name)
 {
        d->fi.setFile(toqstr(name));
-       BOOST_ASSERT(d->fi.isAbsolute());
 }
 
 
@@ -161,11 +166,12 @@ void FileName::erase()
 
 bool FileName::copyTo(FileName const & name) const
 {
+       LYXERR(Debug::FILES, "Copying " << name);
        QFile::remove(name.d->fi.absoluteFilePath());
        bool success = QFile::copy(d->fi.absoluteFilePath(), name.d->fi.absoluteFilePath());
        if (!success)
-               lyxerr << "FileName::copyTo(): Could not copy file "
-                       << *this << " to " << name << endl;
+               LYXERR0("FileName::copyTo(): Could not copy file "
+                       << *this << " to " << name);
        return success;
 }
 
@@ -193,11 +199,6 @@ bool FileName::moveTo(FileName const & name) const
 
 bool FileName::changePermission(unsigned long int mode) const
 {
-       if (!isWritable()) {
-               LYXERR0("File " << *this << " is not writable!");
-               return false;
-       }
-
 #if defined (HAVE_CHMOD) && defined (HAVE_MODE_T)
        if (::chmod(toFilesystemEncoding().c_str(), mode_t(mode)) != 0) {
                LYXERR0("File " << *this << ": cannot change permission to "
@@ -261,13 +262,21 @@ bool FileName::isReadableDirectory() const
 
 string FileName::onlyFileName() const
 {
-       return support::onlyFilename(absFilename());
+       return fromqstr(d->fi.fileName());
+}
+
+
+string FileName::onlyFileNameWithoutExt() const
+{
+       return fromqstr(d->fi.baseName());
 }
 
 
 FileName FileName::onlyPath() const
 {
-       return FileName(support::onlyPath(absFilename()));
+       FileName path;
+       path.d->fi.setFile(d->fi.path());
+       return path;
 }
 
 
@@ -406,6 +415,10 @@ FileName FileName::getcwd()
 
 time_t FileName::lastModified() const
 {
+       // QFileInfo caches information about the file. So, in case this file has
+       // been touched between the object creation and now, we refresh the file
+       // information.
+       d->fi.refresh();
        return d->fi.lastModified().toTime_t();
 }
 
@@ -521,14 +534,14 @@ static int mymkdir(char const * pathname, unsigned long int mode)
 
 bool FileName::createDirectory(int permission) const
 {
-       BOOST_ASSERT(!empty());
+       LASSERT(!empty(), /**/);
        return mymkdir(toFilesystemEncoding().c_str(), permission) == 0;
 }
 
 
 bool FileName::createPath() const
 {
-       BOOST_ASSERT(!empty());
+       LASSERT(!empty(), /**/);
        if (isDirectory())
                return true;
 
@@ -851,8 +864,11 @@ DocFileName::DocFileName(FileName const & abs_filename, bool save_abs)
 
 void DocFileName::set(string const & name, string const & buffer_path)
 {
-       save_abs_path_ = absolutePath(name);
-       FileName::set(save_abs_path_ ? name : makeAbsPath(name, buffer_path).absFilename());
+       FileName::set(name);
+       bool const nameIsAbsolute = isAbsolute();
+       save_abs_path_ = nameIsAbsolute;
+       if (!nameIsAbsolute)
+               FileName::set(makeAbsPath(name, buffer_path).absFilename());
        zipped_valid_ = false;
 }