mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-29 05:01:49 +00:00
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
This commit is contained in:
parent
ec49fff94d
commit
6d20abb1b1
@ -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
|
||||
|
@ -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
|
||||
|
@ -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 << "'"
|
||||
|
@ -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));
|
||||
|
@ -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"
|
||||
|
@ -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 \
|
||||
|
@ -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 <config.h>
|
||||
|
||||
#include <fstream>
|
||||
|
||||
#include "support/FileName.h"
|
||||
#include "support/lyxlib.h"
|
||||
|
||||
#ifdef HAVE_SYS_STAT_H
|
||||
# include <sys/stat.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_TYPES_H
|
||||
# include <sys/types.h>
|
||||
#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
|
@ -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
|
||||
|
@ -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 <config.h>
|
||||
|
||||
#include "support/lyxlib.h"
|
||||
#include "support/FileName.h"
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
|
||||
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
|
Loading…
Reference in New Issue
Block a user