From 6d20abb1b1573b4a77e01a6b555af0bfa9fe1b48 Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Thu, 13 Dec 2007 12:03:55 +0000 Subject: [PATCH] get rid of lyxlib.h:copy() and rename(). git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@22129 a592a061-630c-0410-9148-cb99ea01b6c8 --- development/scons/scons_manifest.py | 2 - src/Buffer.cpp | 4 +- src/insets/InsetBibtex.cpp | 4 +- src/insets/InsetGraphics.cpp | 2 +- src/insets/InsetInclude.cpp | 2 +- src/support/Makefile.am | 2 - src/support/copy.cpp | 68 ----------------------------- src/support/lyxlib.h | 8 ---- src/support/rename.cpp | 35 --------------- 9 files changed, 6 insertions(+), 121 deletions(-) delete mode 100644 src/support/copy.cpp delete mode 100644 src/support/rename.cpp diff --git a/development/scons/scons_manifest.py b/development/scons/scons_manifest.py index a133d9b13b..2faeec1f53 100644 --- a/development/scons/scons_manifest.py +++ b/development/scons/scons_manifest.py @@ -341,7 +341,6 @@ src_support_files = Split(''' Timeout.cpp abort.cpp convert.cpp - copy.cpp debug.cpp docstream.cpp docstring.cpp @@ -356,7 +355,6 @@ src_support_files = Split(''' lyxtime.cpp mkdir.cpp os.cpp - rename.cpp socktools.cpp tempname.cpp unicode.cpp diff --git a/src/Buffer.cpp b/src/Buffer.cpp index 53fc334544..ad4a0e92ab 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -845,7 +845,7 @@ bool Buffer::save() const } else { // Saving failed, so backup is not backup if (madeBackup) - rename(backupName, d->filename); + backupName.renameTo(d->filename); return false; } } @@ -1989,7 +1989,7 @@ int AutoSaveBuffer::generateChild() if (!tmp_ret.empty()) { buffer_.writeFile(tmp_ret); // assume successful write of tmp_ret - if (!rename(tmp_ret, fname_)) { + if (!tmp_ret.renameTo(fname_)) { failed = true; // most likely couldn't move between // filesystems unless write of tmp_ret diff --git a/src/insets/InsetBibtex.cpp b/src/insets/InsetBibtex.cpp index 0c6ee63bb1..9f9d21398a 100644 --- a/src/insets/InsetBibtex.cpp +++ b/src/insets/InsetBibtex.cpp @@ -179,7 +179,7 @@ int InsetBibtex::latex(Buffer const & buffer, odocstream & os, FileName const out_file = makeAbsPath(database + ".bib", buffer.masterBuffer()->temppath()); - bool const success = copy(in_file, out_file); + bool const success = in_file.copyTo(out_file); if (!success) { lyxerr << "Failed to copy '" << in_file << "' to '" << out_file << "'" @@ -238,7 +238,7 @@ int InsetBibtex::latex(Buffer const & buffer, odocstream & os, base = removeExtension(in_file.mangledFilename()); FileName const out_file(makeAbsPath(base + ".bst", buffer.masterBuffer()->temppath())); - bool const success = copy(in_file, out_file); + bool const success = in_file.copyTo(out_file); if (!success) { lyxerr << "Failed to copy '" << in_file << "' to '" << out_file << "'" diff --git a/src/insets/InsetGraphics.cpp b/src/insets/InsetGraphics.cpp index 3b33d9957f..cfb602cb3c 100644 --- a/src/insets/InsetGraphics.cpp +++ b/src/insets/InsetGraphics.cpp @@ -688,7 +688,7 @@ string const InsetGraphics::prepareFile(Buffer const & buf, // the file format from the extension, so we must // change it. FileName const new_file = FileName(changeExtension(temp_file.absFilename(), ext)); - if (rename(temp_file, new_file)) { + if (temp_file.renameTo(new_file)) { temp_file = new_file; output_file = changeExtension(output_file, ext); source_file = FileName(changeExtension(source_file.absFilename(), ext)); diff --git a/src/insets/InsetInclude.cpp b/src/insets/InsetInclude.cpp index 6faf674efa..b6a4f0bc6d 100644 --- a/src/insets/InsetInclude.cpp +++ b/src/insets/InsetInclude.cpp @@ -475,7 +475,7 @@ int InsetInclude::latex(Buffer const & buffer, odocstream & os, unsigned long const checksum_out = writefile.checksum(); if (checksum_in != checksum_out) { - if (!copy(included_file, writefile)) { + if (!included_file.copyTo(writefile)) { // FIXME UNICODE LYXERR(Debug::LATEX, to_utf8(bformat(_("Could not copy the file\n%1$s\n" diff --git a/src/support/Makefile.am b/src/support/Makefile.am index e35f66abe0..934d10051d 100644 --- a/src/support/Makefile.am +++ b/src/support/Makefile.am @@ -44,7 +44,6 @@ liblyxsupport_la_SOURCES = \ abort.cpp \ convert.cpp \ convert.h \ - copy.cpp \ copied_ptr.h \ debug.cpp \ debug.h \ @@ -87,7 +86,6 @@ liblyxsupport_la_SOURCES = \ Package.cpp \ Package.h \ qstring_helpers.h \ - rename.cpp \ socktools.cpp \ socktools.h \ strfwd.h \ diff --git a/src/support/copy.cpp b/src/support/copy.cpp deleted file mode 100644 index 0bf90ba9ba..0000000000 --- a/src/support/copy.cpp +++ /dev/null @@ -1,68 +0,0 @@ -/** - * \file copy.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 - -#include "support/FileName.h" -#include "support/lyxlib.h" - -#ifdef HAVE_SYS_STAT_H -# include -#endif -#ifdef HAVE_SYS_TYPES_H -# include -#endif - -using namespace std; - -namespace lyx { -namespace support { - -static bool chmod(FileName const & file, unsigned long int mode) -{ -#if defined (HAVE_CHMOD) && defined (HAVE_MODE_T) - if (::chmod(file.toFilesystemEncoding().c_str(), mode_t(mode)) != 0) - return false; -#else - // FIXME: "File permissions are ignored on this system." -#endif - return true; -} - - -bool copy(FileName const & from, FileName const & to, unsigned long int mode) -{ - ifstream ifs(from.toFilesystemEncoding().c_str(), ios::binary | ios::in); - if (!ifs) - return false; - - 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 (!support::chmod(to, mode)) - return false; - } - - ofstream ofs(to.toFilesystemEncoding().c_str(), - ios::binary | ios::out | ios::trunc); - if (!ofs) - return false; - - ofs << ifs.rdbuf(); - return ofs.good(); -} - -} // namespace support -} // namespace lyx diff --git a/src/support/lyxlib.h b/src/support/lyxlib.h index 4e6cf32322..4096bc8d94 100644 --- a/src/support/lyxlib.h +++ b/src/support/lyxlib.h @@ -26,14 +26,6 @@ namespace support { /// get the current working directory FileName const getcwd(); -/** - * rename a file, returns false if it fails. - * It can handle renames across partitions. - */ -bool rename(FileName const & from, FileName const & to); -/// copy a file, returns false it it fails -bool copy(FileName const & from, FileName const & to, - unsigned long int mode = (unsigned long int)-1); /// FIXME: some point to this hmm ? int kill(int pid, int sig); /// FIXME: same here diff --git a/src/support/rename.cpp b/src/support/rename.cpp deleted file mode 100644 index 9a18e58a2d..0000000000 --- a/src/support/rename.cpp +++ /dev/null @@ -1,35 +0,0 @@ -/** - * \file rename.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" - -#include - - -namespace lyx { -namespace support { - -bool rename(FileName const & from, FileName const & to) -{ - if (::rename(from.toFilesystemEncoding().c_str(), - to.toFilesystemEncoding().c_str()) != -1) - return true; - if (!copy(from, to)) - return false; - from.removeFile(); - return true; -} - - -} // namespace support -} // namespace lyx -- 2.39.5