diff --git a/src/support/FileName.cpp b/src/support/FileName.cpp index 5704d2cb02..67a9b8579a 100644 --- a/src/support/FileName.cpp +++ b/src/support/FileName.cpp @@ -236,6 +236,12 @@ std::time_t FileName::lastModified() const } +bool FileName::chdir() const +{ + return QDir::setCurrent(d->fi.absoluteFilePath()); +} + + extern unsigned long sum(char const * file); unsigned long FileName::checksum() const diff --git a/src/support/FileName.h b/src/support/FileName.h index b6a4d85086..3577ed9c38 100644 --- a/src/support/FileName.h +++ b/src/support/FileName.h @@ -136,6 +136,9 @@ public: /// used for display in the Gui docstring displayName(int threshold = 1000) const; + /// change to a directory, return success + bool chdir() const; + //private: friend class DocFileName; /// diff --git a/src/support/Makefile.am b/src/support/Makefile.am index c689469f3c..3e69f53f00 100644 --- a/src/support/Makefile.am +++ b/src/support/Makefile.am @@ -24,7 +24,6 @@ liblyxsupport_la_SOURCES = \ FileMonitor.cpp \ RandomAccessList.h \ abort.cpp \ - chdir.cpp \ convert.cpp \ convert.h \ copy.cpp \ diff --git a/src/support/Path.cpp b/src/support/Path.cpp index 147efd07e5..8b85471c97 100644 --- a/src/support/Path.cpp +++ b/src/support/Path.cpp @@ -28,7 +28,7 @@ PathChanger::PathChanger(FileName const & path) if (!path.empty()) { pushedDir_ = getcwd(); - if (pushedDir_.empty() || chdir(path)) { + if (pushedDir_.empty() || !path.chdir()) { /* FIXME: throw */ } } else { @@ -52,7 +52,7 @@ int PathChanger::pop() return 0; } - if (chdir(pushedDir_)) { + if (!pushedDir_.chdir()) { // should throw an exception // throw DirChangeError(); } diff --git a/src/support/chdir.cpp b/src/support/chdir.cpp deleted file mode 100644 index 7bfca71bdf..0000000000 --- a/src/support/chdir.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/** - * \file chdir.cpp - * This file is part of LyX, the document processor. - * Licence details can be found in the file COPYING. - * - * \author Lars Gullik Bjønnes - * - * Full author contact details are available in file CREDITS. - */ - -#include - -#include "support/lyxlib.h" - -#include "support/FileName.h" - -#ifdef HAVE_UNISTD_H -# include -#endif - -#ifdef _WIN32 -# include -#endif - - -namespace lyx { - -int support::chdir(FileName const & name) -{ -#ifdef _WIN32 - return SetCurrentDirectory(name.toFilesystemEncoding().c_str()) != 0 ? 0 : -1; -#else - return ::chdir(name.toFilesystemEncoding().c_str()); -#endif -} - - -} // namespace lyx diff --git a/src/support/lyxlib.h b/src/support/lyxlib.h index f2cfaa6bdb..b7952d2868 100644 --- a/src/support/lyxlib.h +++ b/src/support/lyxlib.h @@ -25,8 +25,6 @@ namespace support { /// get the current working directory FileName const getcwd(); -/// change to a directory, 0 is returned on success. -int chdir(FileName const & name); /// Change file permissions bool chmod(FileName const & file, unsigned long int mode); /** diff --git a/src/support/mkdir.cpp b/src/support/mkdir.cpp index 366f340064..d96dca007b 100644 --- a/src/support/mkdir.cpp +++ b/src/support/mkdir.cpp @@ -11,6 +11,7 @@ #include #include "support/lyxlib.h" +#include "support/debug.h" #include "support/FileName.h" #ifdef HAVE_SYS_STAT_H @@ -36,6 +37,7 @@ namespace support { int mymkdir(char const * pathname, unsigned long int mode) { + LYXERR0("MKDIR" << pathname); // FIXME: why don't we have mode_t in lyx::mkdir prototype ?? #if HAVE_MKDIR # if MKDIR_TAKES_ONE_ARG