mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-25 19:07:45 +00:00
Simplify FileName::tempName().
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@22163 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
a53bbb6f5d
commit
86506a80eb
@ -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
|
||||
|
@ -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();
|
||||
|
@ -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...
|
||||
|
@ -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
|
||||
|
@ -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.
|
||||
|
@ -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;
|
||||
|
@ -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)
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user