backupName = FileName(addName(lyxrc.backupdir_path,
mangledName));
}
- if (fileName().copyTo(backupName)) {
+ if (fileName().copyTo(backupName, true)) {
madeBackup = true;
} else {
Alert::error(_("Backup failure"),
// filesystems unless write of tmp_ret
// failed so remove tmp file (if it
// exists)
- unlink(tmp_ret);
+ tmp_ret.removeFile();
}
} else {
failed = true;
return readFile(a);
case 1:
// Here we delete the autosave
- unlink(a);
+ a.removeFile();
break;
default:
return false;
if (!orig_from_name.exists()) {
LYXERR(Debug::FILES, "Not caching file `"
<< orig_from << "' (does not exist anymore).");
- support::unlink(item.cache_name);
+ item.cache_name.removeFile();
continue;
}
> lyxrc.converter_cache_maxage) {
LYXERR(Debug::FILES, "Not caching file `"
<< orig_from << "' (too old).");
- support::unlink(item.cache_name);
+ item.cache_name.removeFile();
continue;
}
if (it2->first == to_format) {
LYXERR(Debug::FILES, "Removing file cache item "
<< it1->first << ' ' << to_format);
- support::unlink(it2->second.cache_name);
+ it2->second.cache_name.removeFile();
format_cache.erase(it2);
// Have to start over again since items in a
// map are not ordered
using support::subst;
using support::suffixIs;
using support::Systemcall;
-using support::unlink;
using support::trim;
namespace os = support::os;
// What files do we have to delete?
// This will at least make latex do all the runs
- unlink(depfile);
+ depfile.removeFile();
// but the reason for the error might be in a generated file...
// bibtex file
FileName const bbl(changeExtension(file.absFilename(), ".bbl"));
- unlink(bbl);
+ bbl.removeFile();
// makeindex file
FileName const ind(changeExtension(file.absFilename(), ".ind"));
- unlink(ind);
+ ind.removeFile();
// nomencl file
FileName const nls(changeExtension(file.absFilename(), ".nls"));
- unlink(nls);
+ nls.removeFile();
// nomencl file (old version of the package)
FileName const gls(changeExtension(file.absFilename(), ".gls"));
- unlink(gls);
+ gls.removeFile();
// Also remove the aux file
FileName const aux(changeExtension(file.absFilename(), ".aux"));
- unlink(aux);
+ aux.removeFile();
}
/**
* Generate a log file and return the filename.
- * It is the caller's responsibility to unlink the
+ * It is the caller's responsibility to remove the
* file after use.
*/
const std::string getLogFile() const;
if (!do_copy(from, to, latex, (unsigned long int)-1))
return false;
- return support::unlink(from) == 0;
+ return from.removeFile();
}
using support::FileName;
using support::rtrim;
using support::split;
-using support::unlink;
using std::endl;
using std::string;
if (fd < 0) {
lyxerr << "LyXComm: Could not open pipe " << filename << '\n'
<< strerror(errno) << endl;
- unlink(filename);
+ filename.removeFile();
return -1;
}
<< '\n' << strerror(errno) << endl;
}
- if (unlink(FileName(filename)) < 0) {
+ if (FileName(filename).removeFile() < 0) {
lyxerr << "LyXComm: Could not remove pipe " << filename
<< '\n' << strerror(errno) << endl;
}
lyxerr << "lyx: Server socket " << fd_
<< " IO error on closing: " << strerror(errno);
}
- support::unlink(address_);
+ address_.removeFile();
LYXERR(Debug::LYXSERVER, "lyx: Server socket quitting");
}
error = !layout2layout(filename, tempfile);
if (!error)
error = read(tempfile, rt);
- support::unlink(tempfile);
+ tempfile.removeFile();
return error;
}
using support::makeDisplayPath;
using support::onlyFilename;
using support::onlyPath;
-using support::unlink;
namespace Alert = frontend::Alert;
using support::makeDisplayPath;
using support::onlyFilename;
using support::tempName;
-using support::unlink;
using support::unzipFile;
using std::endl;
{
zipped_ = false;
if (!unzipped_filename_.empty())
- unlink(unzipped_filename_);
+ unzipped_filename_.removeFile();
unzipped_filename_.erase();
if (remove_loaded_file_ && !file_to_load_.empty())
- unlink(file_to_load_);
+ file_to_load_.removeFile();
remove_loaded_file_ = false;
file_to_load_.erase();
to_.erase();
setStatus(ErrorConverting);
if (zipped_)
- unlink(unzipped_filename_);
+ unzipped_filename_.removeFile();
return;
}
// Clean up after loading.
if (zipped_)
- unlink(unzipped_filename_);
+ unzipped_filename_.removeFile();
if (remove_loaded_file_ && unzipped_filename_ != file_to_load_)
- unlink(file_to_load_);
+ file_to_load_.removeFile();
cl_.disconnect();
// Remove the temp file, we only want the name...
// FIXME: This is unsafe!
- unlink(to_file_base);
+ to_file_base.removeFile();
// Connect a signal to this->imageConverted and pass this signal to
// the graphics converter so that we can load the modified file
using support::quote_python;
using support::subst;
using support::tempName;
-using support::unlink;
using std::endl;
using std::ostream;
finished_ = true;
// Clean-up behind ourselves
- unlink(script_file_);
+ script_file_.removeFile();
if (retval > 0) {
- unlink(to_file_);
+ to_file_.removeFile();
to_file_.erase();
finishedConversion(false);
} else {
static int counter = 0;
string const tmp = "gconvert" + convert<string>(counter++);
FileName const to_base(tempName(FileName(), tmp));
- unlink(to_base);
+ to_base.removeFile();
// Create a copy of the file in case the original name contains
// problematic characters like ' or ". We can work around that problem
PreviewImage::Impl::~Impl()
{
- support::unlink(iloader_.filename());
+ iloader_.filename().removeFile();
}
case ErrorLoading:
case ErrorGeneratingPixmap:
case ErrorUnknown:
- //lyx::unlink(iloader_.filename());
+ //iloader_.filename().removeFile();
ploader_.remove(snippet_);
break;
case Ready:
- support::unlink(iloader_.filename());
+ iloader_.filename().removeFile();
break;
}
ploader_.emitSignal(parent_);
lyx::support::ForkedcallsController::get().kill(pid, 0);
if (!metrics_file.empty())
- lyx::support::unlink(metrics_file);
+ metrics_file.removeFile();
BitmapFile::const_iterator vit = snippets.begin();
BitmapFile::const_iterator vend = snippets.end();
for (; vit != vend; ++vit) {
if (!vit->second.empty())
- lyx::support::unlink(vit->second);
+ vit->second.removeFile();
}
}
{
support::FileName const tempname(support::tempName(support::FileName(), "lyxext"));
// FIXME: This is unsafe
- support::unlink(tempname);
+ tempname.removeFile();
// must have an extension for the converter code to work correctly.
tempname_ = support::FileName(tempname.absFilename() + ".tmp");
}
TempName::~TempName()
{
- support::unlink(tempname_);
+ tempname_.removeFile();
}
using support::FileName;
using support::quoteName;
using support::tempName;
-using support::unlink;
using support::subst;
using std::auto_ptr;
lyxerr << "calling: " << cmd
<< "\ninput: '" << data << "'" << endl;
cmd_ret const ret = runCommand(command);
- unlink(cas_tmpfile);
+ cas_tmpfile.removeFile();
return ret.second;
}
}
-bool FileName::copyTo(FileName const & name) const
+bool FileName::copyTo(FileName const & name, bool overwrite) const
{
- return QFile::copy(d->fi.absoluteFilePath(), name.d->fi.absoluteFilePath());
+ if (overwrite)
+ QFile::remove(name.d->fi.absoluteFilePath());
+ bool success = QFile::copy(d->fi.absoluteFilePath(), name.d->fi.absoluteFilePath());
+ if (!success)
+ lyxerr << "FileName::copyTo(): Could not copy file "
+ << *this << " to " << name << endl;
+ return success;
}
if (tmpfl.empty())
return false;
- unlink(tmpfl);
+ tmpfl.removeFile();
return true;
}
}
+bool FileName::removeFile() const
+{
+ bool const success = QFile::remove(d->fi.absoluteFilePath());
+ if (!success)
+ lyxerr << "FileName::removeFile(): Could not delete file "
+ << *this << "." << endl;
+ return success;
+}
+
+
static bool rmdir(QFileInfo const & fi)
{
QDir dir(fi.absoluteFilePath());
/// return true when file/directory is writable (write test file)
bool isDirWritable() const;
- /// return true when file/directory is writable (write test file)
- bool copyTo(FileName const & target) const;
+ /// copy a file
+ /// \return true when file/directory is writable (write test file)
+ /// \param overwrite: set to true if we should erase the \c target
+ /// file if it exists,
+ bool copyTo(FileName const & target, bool overwrite = false) const;
+
+ /// remove pointed file.
+ /// \retrun true on success.
+ bool removeFile() const;
/// remove directory and all contents, returns true on success
bool destroyDirectory() const;
userinfo.h \
unicode.cpp \
unicode.h \
- unlink.cpp \
minizip/crypt.h \
minizip/ioapi.c \
minizip/ioapi.h \
// 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
// safe because of the gap between unlink and mkdir. (Lgb)
- unlink(tmpfl);
+ tmpfl.removeFile();
if (tmpfl.empty() || mkdir(tmpfl, 0700)) {
lyxerr << "LyX could not create the temporary directory '"
a += '#';
FileName const autosave(a);
if (autosave.exists())
- unlink(autosave);
+ autosave.removeFile();
}
LYXERR(Debug::GRAPHICS, "[readBB_from_PSFile] " << message);
// FIXME: Why is this func deleting a file? (Lgb)
if (zipped)
- unlink(file);
+ file.removeFile();
}
#include <config.h>
#include "support/lyxlib.h"
-#include "support/docstring.h"
-#include "support/os.h"
-
-#include <boost/scoped_array.hpp>
-
-#include <cerrno>
-
-#ifdef HAVE_UNISTD_H
-# include <unistd.h>
-#endif
-
-#ifdef _WIN32
-# include <windows.h>
-#endif
-
-using boost::scoped_array;
-
-using std::string;
-
namespace lyx {
namespace support {
-namespace {
-
-inline
-char * l_getcwd(char * buffer, size_t size)
-{
-#ifdef _WIN32
- GetCurrentDirectory(size, buffer);
- return buffer;
-#else
- return ::getcwd(buffer, size);
-#endif
-}
-
-} // namespace anon
-
-
// Returns current working directory
FileName const getcwd()
{
- int n = 256; // Assume path is less than 256 chars
- char * err;
- scoped_array<char> tbuf(new char[n]);
-
- // Safe. Hopefully all getcwds behave this way!
- while (((err = l_getcwd(tbuf.get(), n)) == 0) && (errno == ERANGE)) {
- // Buffer too small, double the buffersize and try again
- n *= 2;
- tbuf.reset(new char[n]);
- }
-
- string result;
- if (err)
- result = tbuf.get();
- return FileName(os::internal_path(to_utf8(from_filesystem8bit(result))));
+ return FileName(".");
}
} // namespace support
/// intermediate directories if necessary
/// \ret return 0 if the directory is successfully created
int makedir(char * pathname, unsigned long int mode=0755);
-/// unlink the given file
-int unlink(FileName const & file);
/// (securely) create a temporary file in the given dir with the given mask
/// \p mask must be in filesystem encoding
FileName const tempName(FileName const & dir = FileName(),
{
if (::rename(from.toFilesystemEncoding().c_str(), to.toFilesystemEncoding().c_str()) == -1) {
if (copy(from, to)) {
- unlink(from);
+ from.removeFile();
return true;
} else
return false;
LYXERR(Debug::ANY, "lyx: Could not bind address '" << name.absFilename()
<< "' to socket descriptor: " << strerror(errno));
::close(fd);
- unlink(name);
+ name.removeFile();
return -1;
}
LYXERR(Debug::ANY, "lyx: Could not put socket in 'listen' state: "
<< strerror(errno));
::close(fd);
- unlink(name);
+ name.removeFile();
return -1;
}
+++ /dev/null
-/**
- * \file unlink.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"
-
-#ifdef HAVE_UNISTD_H
-# include <unistd.h>
-#endif
-
-namespace lyx {
-namespace support {
-
-int unlink(FileName const & pathname)
-{
- return ::unlink(pathname.toFilesystemEncoding().c_str());
-}
-
-
-} // namespace support
-} // namespace lyx