- LYXERR(Debug::FILES, "Unable to create temporary file with following template: "
- << qt_tmp.fileTemplate());
- return string();
+
+ // OK, we need another name. Simply append digits.
+ FileName tmp = tempfile;
+ string ext;
+ if (!dir) {
+ // Store and remove extensions
+ ext = "." + tempfile.extension();
+ tmp.changeExtension("");
+ }
+ for (int i = 1; i < INT_MAX ;++i) {
+ // Append digit to filename and re-add extension
+ string const new_fn =
+ tmp.absFileName() + convert<string>(i) + ext;
+ if (tmp_names_.find(new_fn) == tmp_names_.end()) {
+ tmp_names_.insert(new_fn);
+ tempfile.set(new_fn);
+ return tempfile;
+ }
+ }
+
+ // This should not happen!
+ LYXERR0("tempFileName(): Could not create unique temp file name!");
+ return tempfile;
+}
+
+
+void removeTempFile(FileName const & fn)
+{
+ if (!fn.exists())
+ return;
+
+ string const abs = fn.absFileName();
+ if (tmp_names_.find(abs) != tmp_names_.end())
+ tmp_names_.erase(abs);
+ fn.removeFile();