]> git.lyx.org Git - lyx.git/commitdiff
Simplify FileName::tempName().
authorAbdelrazak Younes <younes@lyx.org>
Sun, 16 Dec 2007 09:52:36 +0000 (09:52 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Sun, 16 Dec 2007 09:52:36 +0000 (09:52 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@22163 a592a061-630c-0410-9148-cb99ea01b6c8

src/Buffer.cpp
src/LyXVC.cpp
src/graphics/GraphicsCacheItem.cpp
src/graphics/GraphicsConverter.cpp
src/insets/InsetExternal.cpp
src/mathed/MathExtern.cpp
src/support/FileName.cpp
src/support/FileName.h
src/support/filetools.cpp

index f0787ab4ba6156948a13ca75fbfdebf04b9e5a85..c54a9874861f862a25e9e60040941b3573a9b2b4 100644 (file)
@@ -1922,7 +1922,7 @@ int AutoSaveBuffer::generateChild()
                // anyway.
                bool failed = false;
 
-               FileName const tmp_ret = FileName::tempName(FileName(), "lyxauto");
+               FileName const tmp_ret = FileName::tempName("lyxauto");
                if (!tmp_ret.empty()) {
                        buffer_.writeFile(tmp_ret);
                        // assume successful write of tmp_ret
index 4518a8076c9bf880cec5acaec2276cc02bd7bb58..ff903417fd9c14512d7735a059499c68681681ef 100644 (file)
@@ -217,7 +217,7 @@ string const LyXVC::getLogFile() const
        if (!vcs)
                return string();
 
-       FileName const tmpf = FileName::tempName(FileName(), "lyxvclog");
+       FileName const tmpf = FileName::tempName("lyxvclog");
        if (tmpf.empty()) {
                LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
                return string();
index f9fbce598b64da0c2dd6c4d249446cad49872eba..140ed5ccadc4262d485ae73929c5b328101b4dc0 100644 (file)
@@ -372,7 +372,7 @@ void CacheItem::Impl::convertToDisplayFormat()
        FileName filename;
        zipped_ = filename_.isZippedFile();
        if (zipped_) {
-               unzipped_filename_ = FileName::tempName(FileName(),
+               unzipped_filename_ = FileName::tempName(
                        filename_.toFilesystemEncoding());
                if (unzipped_filename_.empty()) {
                        setStatus(ErrorConverting);
@@ -416,7 +416,7 @@ void CacheItem::Impl::convertToDisplayFormat()
 
        // Add some stuff to create a uniquely named temporary file.
        // This file is deleted in loadImage after it is loaded into memory.
-       FileName const to_file_base = FileName::tempName(FileName(), "CacheItem");
+       FileName const to_file_base = FileName::tempName("CacheItem");
        remove_loaded_file_ = true;
 
        // Remove the temp file, we only want the name...
index 2898f624f4ab56de307e4ee916cd87b493beaf4a..f9847d8cdb7929a1dbfc8b035768d224f148a0b0 100644 (file)
@@ -293,7 +293,7 @@ static void build_script(FileName const & from_file,
        // Remember to remove the temp file because we only want the name...
        static int counter = 0;
        string const tmp = "gconvert" + convert<string>(counter++);
-       FileName const to_base = FileName::tempName(FileName(), tmp);
+       FileName const to_base = FileName::tempName(tmp);
        to_base.removeFile();
 
        // Create a copy of the file in case the original name contains
index a58af2a068121cf21784a26c0b1ae0fedbd20c09..f7f5595ceb573ef4f6484c32227f5c19d0a42732 100644 (file)
@@ -65,7 +65,7 @@ namespace external {
 
 TempName::TempName()
 {
-       FileName const tempname = FileName::tempName(FileName(), "lyxext");
+       FileName const tempname = FileName::tempName("lyxext");
        // FIXME: This is unsafe
        tempname.removeFile();
        // must have an extension for the converter code to work correctly.
index 1a9938dbe254a06fbae5715766b165edd3280dd2..c6447cc68f2b28a9a585682420f6b8493dc61317 100644 (file)
@@ -1020,7 +1020,7 @@ namespace {
        {
                // In order to avoid parsing problems with command interpreters
                // we pass input data through a file
-               FileName const cas_tmpfile = FileName::tempName(FileName(), "casinput");
+               FileName const cas_tmpfile = FileName::tempName("casinput");
                if (cas_tmpfile.empty()) {
                        lyxerr << "Warning: cannot create temporary file."
                               << endl;
index 1abdd5ff042adbb96919740c450804ac0c247b25..f3e73a8bc4dbec8184084be7d9825ae526f058df 100644 (file)
@@ -288,7 +288,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 +357,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)
index dd3932a2dde336e678dc095d971cdfb6f39e6d3c..12319160040b7b6941ba2667003edc3dd7cd7a7d 100644 (file)
@@ -148,10 +148,11 @@ public:
        bool isZippedFile() const;
 
        static FileName fromFilesystemEncoding(std::string const & name);
-       /// (securely) create a temporary file in the given dir with the given mask
-       /// \p mask must be in filesystem encoding
-       static FileName tempName(FileName const & dir = FileName(),
-                                               std::string const & mask = empty_string());
+       /// (securely) create a temporary file with the given mask.
+       /// \p mask must be in filesystem encoding, if it contains a
+       /// relative path, the template file will be created in the global
+       /// temporary directory as given by 'package().temp_dir()'.
+       static FileName tempName(std::string const & mask = empty_string());
 
        /// filename without path
        std::string onlyFileName() const;
index f86fe835f632d059d2263263f774a41c20c912b8..52b7bbadbbc678d517d3e0dad024041b42bf5594 100644 (file)
@@ -322,7 +322,8 @@ static FileName createTmpDir(FileName const & tempdir, string const & mask)
        LYXERR(Debug::FILES, "createTmpDir: tempdir=`" << tempdir << "'\n"
                << "createTmpDir:    mask=`" << mask << '\'');
 
-       FileName const tmpfl = FileName::tempName(tempdir, mask);
+       FileName const tmpfl = FileName::tempName(tempdir.absFilename()
+               + "/" + mask);
        // FileName::tempName actually creates a file to make sure that it
        // stays unique. So we have to delete it before we can create
        // a dir with the same name. Note also that we are not thread