]> git.lyx.org Git - features.git/commitdiff
Simplify Movers API and port to FileName.
authorAbdelrazak Younes <younes@lyx.org>
Thu, 13 Dec 2007 08:20:45 +0000 (08:20 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Thu, 13 Dec 2007 08:20:45 +0000 (08:20 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@22119 a592a061-630c-0410-9148-cb99ea01b6c8

src/ConverterCache.cpp
src/Mover.cpp
src/Mover.h

index cdb8ae20bc34ae6494481a7d48d09fe1614b33b8..41072302cd93952b5544728988f74aef36f21ebe 100644 (file)
@@ -249,6 +249,21 @@ void ConverterCache::init()
 }
 
 
 }
 
 
+static bool changeMode(FileName const & fname, unsigned long int mode)
+{
+       if (mode == (unsigned long int)-1)
+               return true;
+
+       ofstream ofs(fname.toFilesystemEncoding().c_str(), ios::binary | ios::out | ios::trunc);
+       if (!ofs)
+               return false;
+       ofs.close();
+       if (!chmod(fname, mode))
+               return false;
+       return true;
+}
+
+
 void ConverterCache::add(FileName const & orig_from, string const & to_format,
                FileName const & converted_file) const
 {
 void ConverterCache::add(FileName const & orig_from, string const & to_format,
                FileName const & converted_file) const
 {
@@ -289,15 +304,24 @@ void ConverterCache::add(FileName const & orig_from, string const & to_format,
                }
                item->checksum = checksum;
                if (!mover.copy(converted_file, item->cache_name,
                }
                item->checksum = checksum;
                if (!mover.copy(converted_file, item->cache_name,
-                               onlyFilename(item->cache_name.absFilename()), 0600)) {
-                       LYXERR(Debug::FILES, "ConverterCache::add(" << orig_from << "):\n"
-                                               "Could not copy file.");
+                             onlyFilename(item->cache_name.absFilename()))) {
+                       LYXERR(Debug::FILES, "Could not copy file " << orig_from << " to "
+                               << item->cache_name);
+               } else if (!changeMode(item->cache_name, 0600)) {
+                       LYXERR(Debug::FILES, "Could not change file mode"
+                               << item->cache_name);
                }
        } else {
                CacheItem new_item(orig_from, to_format, timestamp,
                                orig_from.checksum());
                }
        } else {
                CacheItem new_item(orig_from, to_format, timestamp,
                                orig_from.checksum());
+               // FIXME: The original code used to chmod the new file to 600.
+               // See SpecialisedMover::do_copy().
                if (mover.copy(converted_file, new_item.cache_name,
                if (mover.copy(converted_file, new_item.cache_name,
-                              onlyFilename(new_item.cache_name.absFilename()), 0600)) {
+                             onlyFilename(new_item.cache_name.absFilename()))) {
+                       if (!changeMode(item->cache_name, 0600)) {
+                               LYXERR(Debug::FILES, "Could not change file mode"
+                                       << item->cache_name);
+                       }
                        FormatCache & format_cache = pimpl_->cache[orig_from];
                        if (format_cache.from_format.empty())
                                format_cache.from_format =
                        FormatCache & format_cache = pimpl_->cache[orig_from];
                        if (format_cache.from_format.empty())
                                format_cache.from_format =
index bf089be2947036e2b6590bd9fb05312ae83bbab9..bdcf4e04bbf6afa394cd6faf00c0c80a2aa7249d 100644 (file)
@@ -26,17 +26,16 @@ using namespace lyx::support;
 namespace lyx {
 
 
 namespace lyx {
 
 
-bool Mover::copy(FileName const & from, FileName const & to,
-                unsigned long int mode) const
+bool Mover::copy(FileName const & from, FileName const & to) const
 {
 {
-       return do_copy(from, to, to.absFilename(), mode);
+       return do_copy(from, to, to.absFilename());
 }
 
 
 bool Mover::do_copy(FileName const & from, FileName const & to,
 }
 
 
 bool Mover::do_copy(FileName const & from, FileName const & to,
-                   string const &, unsigned long int mode) const
+                   string const &) const
 {
 {
-       return support::copy(from, to, mode);
+       return from.copyTo(to);
 }
 
 
 }
 
 
@@ -50,24 +49,15 @@ bool Mover::rename(FileName const & from,
 bool Mover::do_rename(FileName const & from, FileName const & to,
                      string const &) const
 {
 bool Mover::do_rename(FileName const & from, FileName const & to,
                      string const &) const
 {
-       return rename(from, to);
+       return from.renameTo(to);
 }
 
 
 bool SpecialisedMover::do_copy(FileName const & from, FileName const & to,
 }
 
 
 bool SpecialisedMover::do_copy(FileName const & from, FileName const & to,
-                              string const & latex, unsigned long int mode) const
+                              string const & latex) const
 {
        if (command_.empty())
 {
        if (command_.empty())
-               return Mover::do_copy(from, to, latex, mode);
-
-       if (mode != (unsigned long int)-1) {
-               ofstream ofs(to.toFilesystemEncoding().c_str(), ios::binary | ios::out | ios::trunc);
-               if (!ofs)
-                       return false;
-               ofs.close();
-               if (!chmod(to, mode))
-                       return false;
-       }
+               return Mover::do_copy(from, to, latex);
 
        string command = libScriptSearch(command_);
        command = subst(command, "$$i", quoteName(from.toFilesystemEncoding()));
 
        string command = libScriptSearch(command_);
        command = subst(command, "$$i", quoteName(from.toFilesystemEncoding()));
@@ -85,7 +75,7 @@ bool SpecialisedMover::do_rename(FileName const & from, FileName const & to,
        if (command_.empty())
                return Mover::do_rename(from, to, latex);
 
        if (command_.empty())
                return Mover::do_rename(from, to, latex);
 
-       if (!do_copy(from, to, latex, (unsigned long int)-1))
+       if (!do_copy(from, to, latex))
                return false;
        return from.removeFile();
 }
                return false;
        return from.removeFile();
 }
index 7c0c5021f0e869443b145dc43a68957449a90f41..3f4585bb53217d13047fdf8e7b1f1d18b5ce260a 100644 (file)
@@ -36,8 +36,7 @@ public:
         *  \returns true if successful.
         */
        bool
         *  \returns true if successful.
         */
        bool
-       copy(support::FileName const & from, support::FileName const & to,
-            unsigned long int mode = (unsigned long int)-1) const;
+       copy(support::FileName const & from, support::FileName const & to) const;
 
        /** Copy file @c from to @c to.
         *  \see SpecialisedMover::SpecialisedMover() for an explanation of
 
        /** Copy file @c from to @c to.
         *  \see SpecialisedMover::SpecialisedMover() for an explanation of
@@ -49,10 +48,9 @@ public:
         */
        bool
        copy(support::FileName const & from, support::FileName const & to,
         */
        bool
        copy(support::FileName const & from, support::FileName const & to,
-            std::string const & latex,
-            unsigned long int mode = (unsigned long int)-1) const
+            std::string const & latex) const
        {
        {
-               return do_copy(from, to, latex, mode);
+               return do_copy(from, to, latex);
        }
 
        /** Rename file @c from as @c to.
        }
 
        /** Rename file @c from as @c to.
@@ -82,7 +80,7 @@ public:
 protected:
        virtual bool
        do_copy(support::FileName const & from, support::FileName const & to,
 protected:
        virtual bool
        do_copy(support::FileName const & from, support::FileName const & to,
-               std::string const &, unsigned long int mode) const;
+               std::string const &) const;
 
        virtual bool
        do_rename(support::FileName const & from, support::FileName const & to,
 
        virtual bool
        do_rename(support::FileName const & from, support::FileName const & to,
@@ -131,7 +129,7 @@ public:
 private:
        virtual bool
        do_copy(support::FileName const & from, support::FileName const & to,
 private:
        virtual bool
        do_copy(support::FileName const & from, support::FileName const & to,
-               std::string const & latex, unsigned long int mode) const;
+               std::string const & latex) const;
 
        virtual bool
        do_rename(support::FileName const & from, support::FileName const & to,
 
        virtual bool
        do_rename(support::FileName const & from, support::FileName const & to,