]> git.lyx.org Git - lyx.git/blobdiff - src/support/FileName.cpp
zipunzip.cpp: Replace makedir etc with versions in support::FileName, fix a bug in...
[lyx.git] / src / support / FileName.cpp
index 1abdd5ff042adbb96919740c450804ac0c247b25..e847ecc5a2ace72d7073febeb51644fb4e69e23d 100644 (file)
@@ -17,7 +17,6 @@
 #include "support/debug.h"
 #include "support/filetools.h"
 #include "support/lstrings.h"
-#include "support/lyxlib.h"
 #include "support/os.h"
 #include "support/Package.h"
 #include "support/qstring_helpers.h"
@@ -141,6 +140,12 @@ bool FileName::empty() const
 }
 
 
+bool FileName::isAbsolute() const
+{
+       return d->fi.isAbsolute();
+}
+
+
 string FileName::absFilename() const
 {
        return fromqstr(d->fi.absoluteFilePath());
@@ -150,7 +155,6 @@ string FileName::absFilename() const
 void FileName::set(string const & name)
 {
        d->fi.setFile(toqstr(name));
-       BOOST_ASSERT(d->fi.isAbsolute());
 }
 
 
@@ -194,11 +198,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 "
@@ -262,13 +261,15 @@ bool FileName::isReadableDirectory() const
 
 string FileName::onlyFileName() const
 {
-       return support::onlyFilename(absFilename());
+       return fromqstr(d->fi.fileName());
 }
 
 
 FileName FileName::onlyPath() const
 {
-       return FileName(support::onlyPath(absFilename()));
+       FileName path;
+       path.d->fi.setFile(d->fi.path());
+       return path;
 }
 
 
@@ -288,7 +289,7 @@ bool FileName::isDirWritable() const
 {
        LYXERR(Debug::FILES, "isDirWriteable: " << *this);
 
-       FileName const tmpfl = FileName::tempName(*this, "lyxwritetest");
+       FileName const tmpfl = FileName::tempName(absFilename() + "/lyxwritetest");
 
        if (tmpfl.empty())
                return false;
@@ -357,11 +358,15 @@ static int make_tempfile(char * templ)
 }
 
 
-FileName FileName::tempName(FileName const & dir, string const & mask)
+FileName FileName::tempName(string const & mask)
 {
-       string const tmpdir = dir.empty() ?
-               package().temp_dir().absFilename() : dir.absFilename();
-       string tmpfl = to_filesystem8bit(from_utf8(addName(tmpdir, mask)));
+       FileName tmp_name(mask);
+       string tmpfl;
+       if (tmp_name.d->fi.isAbsolute())
+               tmpfl = mask;
+       else
+               tmpfl = package().temp_dir().absFilename() + "/" + mask;
+
 #if defined (HAVE_GETPID)
        tmpfl += convert<string>(getpid());
 #elif defined (HAVE__GETPID)
@@ -395,6 +400,12 @@ FileName FileName::tempName(FileName const & dir, string const & mask)
 }
 
 
+FileName FileName::getcwd()
+{
+       return FileName(".");
+}
+
+
 time_t FileName::lastModified() const
 {
        return d->fi.lastModified().toTime_t();
@@ -412,7 +423,7 @@ extern unsigned long sum(char const * file);
 unsigned long FileName::checksum() const
 {
        if (!exists()) {
-               LYXERR0("File \"" << absFilename() << "\" does not exist!");
+               //LYXERR0("File \"" << absFilename() << "\" does not exist!");
                return 0;
        }
        // a directory may be passed here so we need to test it. (bug 3622)
@@ -842,8 +853,9 @@ 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);
+       if (!isAbsolute())
+               FileName::set(makeAbsPath(name, buffer_path).absFilename());
        zipped_valid_ = false;
 }