As I wrote in an earlier mail, here is the first step to fix bugs 605, 1231, and 1244: Remove the use_tempdir of lyxrc and use always a temp dir. I found no clean and easy way to make CreateBufferTmpDir() always succeed, so I gave up on that. However, I made CreateLyXTmpDir() always succeed by exiting if the temp dir could not be created. I believe that this is reasonable because CreateLyXTmpDir() tries very hard to create a temp dir and should succeed in almost all cases. If it fails, and LyX would continue, weird things can happen in various places.
The patch furthermore makes some functions const (a leftover from some earlier experiments, but it cannot hurt), some other minor changes and removes the version check of insetgraphics. It is not needed anymore, because lyx2lyx handles this. Things that might be wrong: - Is it ok to read in the lyxrc use_tempdir flag for compatibility reasons, and then ignore it silently? - José, could you check that I got the docbook part in insetinclude right? - The wording of the error message in lyx_main.C can probably be improved. If this is ok, can somebody please apply it? Georg
Index: src/ChangeLog =================================================================== RCS file: /cvs/lyx/lyx-devel/src/ChangeLog,v retrieving revision 1.1806 diff -u -p -r1.1806 ChangeLog --- src/ChangeLog 2004/02/13 09:50:18 1.1806 +++ src/ChangeLog 2004/02/15 19:59:45 @@ -1,3 +1,15 @@ +2004-02-15 Georg Baum <[EMAIL PROTECTED]> + + * lyxrc.C, buffer.C, exporter.C: use always a temp dir, ignore + use_tempdir in preferences + * buffer.C (readFile), lyxvc.C (getLogFile): check success of + tempfile creation + * lyx_main.C: ensure that tempdir is valid + * lyxlex.h: correct typo + * buffer.[Ch] (isMultiLingual), (isUnnamed): make const + * paragraph.[Ch] (isMultiLingual): make const + * cursor.[Ch] (openable): make const + 2004-02-13 Alfredo Braunstein <[EMAIL PROTECTED]> * cursor.C (dispatch): restore current_ before returning Index: src/buffer.C =================================================================== RCS file: /cvs/lyx/lyx-devel/src/buffer.C,v retrieving revision 1.554 diff -u -p -r1.554 buffer.C --- src/buffer.C 2004/02/11 14:45:38 1.554 +++ src/buffer.C 2004/02/15 19:59:52 @@ -85,7 +85,7 @@ using lyx::support::atoi; using lyx::support::bformat; using lyx::support::ChangeExtension; using lyx::support::cmd_ret; -using lyx::support::CreateBufferTmpDir; +using lyx::support::createBufferTmpDir; using lyx::support::destroyDir; using lyx::support::FileInfo; using lyx::support::FileInfo; @@ -190,8 +190,7 @@ Buffer::Impl::Impl(Buffer & parent, stri text(0, 0) { lyxvc.buffer(&parent); - if (readonly_ || lyxrc.use_tempdir) - temppath = CreateBufferTmpDir(); + temppath = createBufferTmpDir(); } @@ -318,11 +317,8 @@ pair<Buffer::LogType, string> const Buff if (filename.empty()) return make_pair(Buffer::latexlog, string()); - string path = OnlyPath(filename); + string const path = temppath(); - if (lyxrc.use_tempdir || !IsDirWriteable(path)) - path = temppath(); - string const fname = AddName(path, OnlyFilename(ChangeExtension(filename, ".log"))); @@ -596,6 +612,15 @@ bool Buffer::readFile(LyXLex & lex, stri filename)); } else if (file_format < LYX_FORMAT) { string const tmpfile = tempName(); + if (tmpfile.empty()) { + Alert::error(_("Conversion failed"), + bformat(_("%1$s is from an earlier" + " version of LyX, but a temporary" + " file for converting it could" + " not be created."), + filename)); + return false; + } string command = LibFileSearch("lyx2lyx", "lyx2lyx"); if (command.empty()) { Alert::error(_("Conversion script not found"), @@ -953,7 +983,7 @@ bool Buffer::isSGML() const void Buffer::makeLinuxDocFile(string const & fname, OutputParams const & runparams, - bool body_only ) + bool body_only) { ofstream ofs; if (!openFileWrite(ofs, fname)) @@ -1074,12 +1110,8 @@ int Buffer::runChktex() // get LaTeX-Filename string const name = getLatexName(); - string path = filePath(); - - string const org_path = path; - if (lyxrc.use_tempdir || !IsDirWriteable(path)) { - path = temppath(); - } + string const path = temppath(); + string const org_path = filePath(); Path p(path); // path to LaTeX file message(_("Running chktex...")); @@ -1272,10 +1298,10 @@ void Buffer::updateDocLang(Language cons } -bool Buffer::isMultiLingual() +bool Buffer::isMultiLingual() const { - ParIterator end = par_iterator_end(); - for (ParIterator it = par_iterator_begin(); it != end; ++it) + ParConstIterator end = par_iterator_end(); + for (ParConstIterator it = par_iterator_begin(); it != end; ++it) if (it->isMultiLingual(params())) return true; @@ -1424,7 +1450,7 @@ void Buffer::setUnnamed(bool flag) } -bool Buffer::isUnnamed() +bool Buffer::isUnnamed() const { return pimpl_->unnamed; } Index: src/buffer.h =================================================================== RCS file: /cvs/lyx/lyx-devel/src/buffer.h,v retrieving revision 1.177 diff -u -p -r1.177 buffer.h --- src/buffer.h 2004/01/26 10:13:08 1.177 +++ src/buffer.h 2004/02/15 19:59:53 @@ -181,7 +181,7 @@ public: void setUnnamed(bool flag = true); /// - bool isUnnamed(); + bool isUnnamed() const; /// Mark this buffer as dirty. void markDirty(); @@ -248,7 +253,7 @@ public: void updateDocLang(Language const * nlang); /// - bool isMultiLingual(); + bool isMultiLingual() const; /// Does this mean that this is buffer local? limited_stack<Undo> & undostack(); Index: src/cursor.C =================================================================== RCS file: /cvs/lyx/lyx-devel/src/cursor.C,v retrieving revision 1.59 diff -u -p -r1.59 cursor.C --- src/cursor.C 2004/02/13 13:51:07 1.59 +++ src/cursor.C 2004/02/15 19:59:59 @@ -857,7 +857,7 @@ bool LCursor::isInside(InsetBase const * } -bool LCursor::openable(MathAtom const & t) +bool LCursor::openable(MathAtom const & t) const { if (!t->isActive()) return false; Index: src/cursor.h =================================================================== RCS file: /cvs/lyx/lyx-devel/src/cursor.h,v retrieving revision 1.36 diff -u -p -r1.36 cursor.h --- src/cursor.h 2004/02/13 13:51:07 1.36 +++ src/cursor.h 2004/02/15 20:00:00 @@ -459,7 +459,7 @@ private: /// where in the curent cell does the macro name start? int macroNamePos(); /// can we enter the inset? - bool openable(MathAtom const &); + bool openable(MathAtom const &) const; }; #endif // LYXCURSOR_H Index: src/exporter.C =================================================================== RCS file: /cvs/lyx/lyx-devel/src/exporter.C,v retrieving revision 1.50 diff -u -p -r1.50 exporter.C --- src/exporter.C 2003/11/27 16:38:47 1.50 +++ src/exporter.C 2004/02/15 20:00:00 @@ -85,8 +127,7 @@ bool Exporter::Export(Buffer * buffer, s backend_format = format; string filename = buffer->getLatexName(false); - if (!buffer->temppath().empty()) - filename = AddName(buffer->temppath(), filename); + filename = AddName(buffer->temppath(), filename); filename = ChangeExtension(filename, formats.extension(backend_format)); Index: src/lyx_main.C =================================================================== RCS file: /cvs/lyx/lyx-devel/src/lyx_main.C,v retrieving revision 1.182 diff -u -p -r1.182 lyx_main.C --- src/lyx_main.C 2003/12/12 13:57:19 1.182 +++ src/lyx_main.C 2004/02/15 20:00:04 @@ -58,7 +58,7 @@ using lyx::support::AddName; using lyx::support::AddPath; using lyx::support::bformat; using lyx::support::createDirectory; -using lyx::support::CreateLyXTmpDir; +using lyx::support::createLyXTmpDir; using lyx::support::FileInfo; using lyx::support::FileSearch; using lyx::support::GetEnv; @@ -390,7 +390,21 @@ void LyX::init(bool gui) if (lyxerr.debugging(Debug::LYXRC)) lyxrc.print(); - os::setTmpDir(CreateLyXTmpDir(lyxrc.tempdir_path)); + os::setTmpDir(createLyXTmpDir(lyxrc.tempdir_path)); + if (os::getTmpDir().empty()) { + Alert::error(_("Could not create temporary directory"), + bformat(_("Could not create a temporary directory in\n" + "%1$s. Make sure that this\n" + "path exists and is writable and try again."), + lyxrc.tempdir_path)); + // createLyXTmpDir() tries sufficiently hard to create a + // usable temp dir, so the probability to come here is + // close to zero. We therefore don't try to overcome this + // problem with e.g. asking the user for a new path and + // trying again but simply exit. + exit(EXIT_FAILURE); + } + if (lyxerr.debugging(Debug::INIT)) { lyxerr << "LyX tmp dir: `" << os::getTmpDir() << '\'' << endl; } Index: src/lyxlex.h =================================================================== RCS file: /cvs/lyx/lyx-devel/src/lyxlex.h,v retrieving revision 1.38 diff -u -p -r1.38 lyxlex.h --- src/lyxlex.h 2003/12/02 12:27:07 1.38 +++ src/lyxlex.h 2004/02/15 20:00:09 @@ -155,7 +155,7 @@ private: This is needed to ensure that the pop is done upon exit from methods with more than one exit point or that can return as a response to exceptions. - @autor Lgb + @author Lgb */ struct pushpophelper { /// Index: src/lyxrc.C =================================================================== RCS file: /cvs/lyx/lyx-devel/src/lyxrc.C,v retrieving revision 1.162 diff -u -p -r1.162 lyxrc.C --- src/lyxrc.C 2003/12/14 16:33:53 1.162 +++ src/lyxrc.C 2004/02/15 20:00:14 @@ -156,6 +157,7 @@ keyword_item lyxrcTags[] = { // compatibility with versions older than 1.4.0 only { "\\use_pspell", LyXRC::RC_USE_SPELL_LIB }, { "\\use_spell_lib", LyXRC::RC_USE_SPELL_LIB }, + // compatibility with versions older than 1.4.0 only { "\\use_tempdir", LyXRC::RC_USETEMPDIR }, { "\\user_email", LyXRC::RC_USER_EMAIL }, { "\\user_name", LyXRC::RC_USER_NAME }, @@ -197,7 +199,6 @@ void LyXRC::setDefaults() { print_paper_dimension_flag = "-T"; document_path.erase(); tempdir_path = "/tmp"; - use_tempdir = true; ps_command = "gs"; view_dvi_paper_option.erase(); default_papersize = PAPER_USLETTER; @@ -657,7 +658,9 @@ int LyXRC::read(string const & filename) case RC_USETEMPDIR: if (lexrc.next()) { - use_tempdir = lexrc.getBool(); + // Ignore it + // FIXME: Tell the user? + lexrc.getBool(); } break; @@ -1524,9 +1540,7 @@ void LyXRC::output(ostream & os) const os << "\\tempdir_path \"" << tempdir_path << "\"\n"; } case RC_USETEMPDIR: - if (use_tempdir != system_lyxrc.use_tempdir) { - os << "\\use_tempdir " << tostr(use_tempdir) << '\n'; - } + // Ignore it case RC_ASCII_LINELEN: if (ascii_linelen != system_lyxrc.ascii_linelen) { os << "\\ascii_linelen " << ascii_linelen << '\n'; @@ -1904,10 +1929,6 @@ string const LyXRC::getDescription(LyXRC str = _("LyX will place its temporary directories in this path. They will be deleted when you quit LyX."); break; - case RC_USETEMPDIR: - str = _("Select if you wish to use a temporary directory structure to store temporary TeX output."); - break; - case RC_LASTFILES: str = _("The file where the last-files information should be stored."); break; Index: src/lyxrc.h =================================================================== RCS file: /cvs/lyx/lyx-devel/src/lyxrc.h,v retrieving revision 1.80 diff -u -p -r1.80 lyxrc.h --- src/lyxrc.h 2003/10/06 15:42:27 1.80 +++ src/lyxrc.h 2004/02/15 20:00:15 @@ -205,8 +206,6 @@ enum LyXRCTags { std::string template_path; /// std::string tempdir_path; - /// - bool use_tempdir; /// bool auto_region_delete; /// flag telling whether lastfiles should be checked for existance Index: src/lyxvc.C =================================================================== RCS file: /cvs/lyx/lyx-devel/src/lyxvc.C,v retrieving revision 1.54 diff -u -p -r1.54 lyxvc.C --- src/lyxvc.C 2003/11/03 17:47:22 1.54 +++ src/lyxvc.C 2004/02/15 20:00:15 @@ -223,6 +223,11 @@ string const LyXVC::getLogFile() const return string(); string tmpf = tempName(string(), "lyxvclog"); + if (tmpf.empty()) { + lyxerr[Debug::LYXVC] << "Could not generate logfile " + << tmpf << endl; + return string(); + } lyxerr[Debug::LYXVC] << "Generating logfile " << tmpf << endl; vcs->getLog(tmpf); return tmpf; Index: src/paragraph.C =================================================================== RCS file: /cvs/lyx/lyx-devel/src/paragraph.C,v retrieving revision 1.353 diff -u -p -r1.353 paragraph.C --- src/paragraph.C 2004/02/12 16:35:58 1.353 +++ src/paragraph.C 2004/02/15 20:00:19 @@ -1553,7 +1553,7 @@ void Paragraph::changeLanguage(BufferPar } -bool Paragraph::isMultiLingual(BufferParams const & bparams) +bool Paragraph::isMultiLingual(BufferParams const & bparams) const { Language const * doc_language = bparams.language; Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin(); Index: src/paragraph.h =================================================================== RCS file: /cvs/lyx/lyx-devel/src/paragraph.h,v retrieving revision 1.125 diff -u -p -r1.125 paragraph.h --- src/paragraph.h 2004/02/12 16:35:59 1.125 +++ src/paragraph.h 2004/02/15 20:00:20 @@ -80,7 +80,7 @@ public: void changeLanguage(BufferParams const & bparams, Language const * from, Language const * to); /// - bool isMultiLingual(BufferParams const &); + bool isMultiLingual(BufferParams const &) const; /// std::string const asString(Buffer const &, Index: src/frontends/controllers/ChangeLog =================================================================== RCS file: /cvs/lyx/lyx-devel/src/frontends/controllers/ChangeLog,v retrieving revision 1.414 diff -u -p -r1.414 ChangeLog --- src/frontends/controllers/ChangeLog 2004/02/01 12:46:11 1.414 +++ src/frontends/controllers/ChangeLog 2004/02/15 20:00:32 @@ -1,3 +1,8 @@ +2004-02-15 Georg Baum <[EMAIL PROTECTED]> + + * ControlPrint.C, ControlSendto.C: use always a tempdir + * ControlSendto.C: check return value of buffer()->writeFile() + 2004-02-01 Lars Gullik Bjonnes <[EMAIL PROTECTED]> * biblio.C (parseBibTeX): "=" -> '=' Index: src/frontends/controllers/ControlPrint.C =================================================================== RCS file: /cvs/lyx/lyx-devel/src/frontends/controllers/ControlPrint.C,v retrieving revision 1.45 diff -u -p -r1.45 ControlPrint.C --- src/frontends/controllers/ControlPrint.C 2004/01/08 10:59:49 1.45 +++ src/frontends/controllers/ControlPrint.C 2004/02/15 20:00:33 @@ -170,10 +170,7 @@ void ControlPrint::apply() } // Push directory path. - string path = buffer()->filePath(); - if (lyxrc.use_tempdir || !IsDirWriteable(path)) { - path = buffer()->temppath(); - } + string const path = buffer()->temppath(); Path p(path); // there are three cases here: Index: src/frontends/controllers/ControlSendto.C =================================================================== RCS file: /cvs/lyx/lyx-devel/src/frontends/controllers/ControlSendto.C,v retrieving revision 1.23 diff -u -p -r1.23 ControlSendto.C --- src/frontends/controllers/ControlSendto.C 2004/01/07 17:57:46 1.23 +++ src/frontends/controllers/ControlSendto.C 2004/02/15 20:00:34 @@ -120,10 +120,10 @@ void ControlSendto::apply() if (format_->name() == "lyx") { filename = ChangeExtension(buffer()->getLatexName(false), format_->extension()); - if (!buffer()->temppath().empty()) - filename = AddName(buffer()->temppath(), filename); + filename = AddName(buffer()->temppath(), filename); - buffer()->writeFile(filename); + if (!buffer()->writeFile(filename)) + return; } else { Exporter::Export(buffer(), format_->name(), true, filename); Index: src/frontends/qt2/ChangeLog =================================================================== RCS file: /cvs/lyx/lyx-devel/src/frontends/qt2/ChangeLog,v retrieving revision 1.641 diff -u -p -r1.641 ChangeLog --- src/frontends/qt2/ChangeLog 2004/02/01 12:46:11 1.641 +++ src/frontends/qt2/ChangeLog 2004/02/15 20:00:44 @@ -1,3 +1,8 @@ +2004-02-15 Georg Baum <[EMAIL PROTECTED]> + + * QPrefs.C, QPrefsDialog.C, ui/QPrefPathsModule.ui: remove + use_tempdir + 2004-02-01 Lars Gullik Bjonnes <[EMAIL PROTECTED]> * floatplacement.C (set): "c" -> 'c' in calls to contains Index: src/frontends/qt2/QPrefs.C =================================================================== RCS file: /cvs/lyx/lyx-devel/src/frontends/qt2/QPrefs.C,v retrieving revision 1.50 diff -u -p -r1.50 QPrefs.C --- src/frontends/qt2/QPrefs.C 2004/01/28 16:21:27 1.50 +++ src/frontends/qt2/QPrefs.C 2004/02/15 20:00:48 @@ -195,7 +195,6 @@ void QPrefs::apply() rc.document_path = fromqstr(pathsmod->workingDirED->text()); rc.template_path = fromqstr(pathsmod->templateDirED->text()); rc.backupdir_path = fromqstr(pathsmod->backupDirED->text()); - rc.use_tempdir = pathsmod->tempDirCB->isChecked(); rc.tempdir_path = fromqstr(pathsmod->tempDirED->text()); // FIXME: should be a checkbox only rc.lyxpipes = fromqstr(pathsmod->lyxserverDirED->text()); @@ -499,7 +498,6 @@ void QPrefs::update_contents() pathsmod->workingDirED->setText(toqstr(rc.document_path)); pathsmod->templateDirED->setText(toqstr(rc.template_path)); pathsmod->backupDirED->setText(toqstr(rc.backupdir_path)); - pathsmod->tempDirCB->setChecked(rc.use_tempdir); pathsmod->tempDirED->setText(toqstr(rc.tempdir_path)); // FIXME: should be a checkbox only pathsmod->lyxserverDirED->setText(toqstr(rc.lyxpipes)); Index: src/frontends/qt2/QPrefsDialog.C =================================================================== RCS file: /cvs/lyx/lyx-devel/src/frontends/qt2/QPrefsDialog.C,v retrieving revision 1.29 diff -u -p -r1.29 QPrefsDialog.C --- src/frontends/qt2/QPrefsDialog.C 2003/10/06 15:42:51 1.29 +++ src/frontends/qt2/QPrefsDialog.C 2004/02/15 20:00:49 @@ -210,7 +210,6 @@ QPrefsDialog::QPrefsDialog(QPrefs * form connect(pathsModule->workingDirED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor())); connect(pathsModule->templateDirED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor())); connect(pathsModule->backupDirED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor())); - connect(pathsModule->tempDirCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor())); connect(pathsModule->tempDirED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor())); connect(pathsModule->lyxserverDirED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor())); connect(spellcheckerModule->spellCommandCO, SIGNAL(activated(int)), this, SLOT(change_adaptor())); Index: src/frontends/qt2/ui/QPrefPathsModule.ui =================================================================== RCS file: /cvs/lyx/lyx-devel/src/frontends/qt2/ui/QPrefPathsModule.ui,v retrieving revision 1.6 diff -u -p -r1.6 QPrefPathsModule.ui --- src/frontends/qt2/ui/QPrefPathsModule.ui 2003/01/23 16:23:40 1.6 +++ src/frontends/qt2/ui/QPrefPathsModule.ui 2004/02/15 20:00:52 @@ -142,14 +142,18 @@ </property> </widget> <widget row="4" column="0" > - <class>QCheckBox</class> + <class>QLabel</class> <property stdset="1"> <name>name</name> - <cstring>tempDirCB</cstring> + <cstring>tempDirLA</cstring> </property> <property stdset="1"> <name>text</name> - <string>&Use temporary directory</string> + <string>&Temporary directory:</string> + </property> + <property> + <name>buddy</name> + <cstring>tempDirED</cstring> </property> </widget> <widget row="3" column="2" > @@ -251,20 +255,6 @@ </spacer> </vbox> </widget> -<connections> - <connection> - <sender>tempDirCB</sender> - <signal>toggled(bool)</signal> - <receiver>tempDirED</receiver> - <slot>setEnabled(bool)</slot> - </connection> - <connection> - <sender>tempDirCB</sender> - <signal>toggled(bool)</signal> - <receiver>tempDirPB</receiver> - <slot>setEnabled(bool)</slot> - </connection> -</connections> <tabstops> <tabstop>workingDirED</tabstop> <tabstop>workingDirPB</tabstop> @@ -274,7 +264,6 @@ <tabstop>backupDirPB</tabstop> <tabstop>lyxserverDirED</tabstop> <tabstop>lyxserverDirPB</tabstop> - <tabstop>tempDirCB</tabstop> <tabstop>tempDirED</tabstop> <tabstop>tempDirPB</tabstop> </tabstops> Index: src/frontends/xforms/ChangeLog =================================================================== RCS file: /cvs/lyx/lyx-devel/src/frontends/xforms/ChangeLog,v retrieving revision 1.877 diff -u -p -r1.877 ChangeLog --- src/frontends/xforms/ChangeLog 2004/02/01 12:46:12 1.877 +++ src/frontends/xforms/ChangeLog 2004/02/15 20:01:10 @@ -1,3 +1,7 @@ +2004-02-15 Georg Baum <[EMAIL PROTECTED]> + + * FormPreferences.C, forms/form_preferences.fd: remove use_tempdir + 2004-02-01 Lars Gullik Bjonnes <[EMAIL PROTECTED]> * FormFloat.C (update): "c" -> 'c' in calls to contains Index: src/frontends/xforms/FormPreferences.C =================================================================== RCS file: /cvs/lyx/lyx-devel/src/frontends/xforms/FormPreferences.C,v retrieving revision 1.181 diff -u -p -r1.181 FormPreferences.C --- src/frontends/xforms/FormPreferences.C 2003/12/15 09:17:04 1.181 +++ src/frontends/xforms/FormPreferences.C 2004/02/15 20:01:18 @@ -1825,17 +1834,10 @@ void FormPreferences::Paths::apply(LyXRC { rc.document_path = fl_get_input(dialog_->input_default_path); rc.template_path = fl_get_input(dialog_->input_template_path); - - int button = fl_get_button(dialog_->check_use_temp_dir); - string str = fl_get_input(dialog_->input_temp_dir); - if (!button) - str.erase(); + rc.tempdir_path = fl_get_input(dialog_->input_temp_dir); - rc.use_tempdir = button; - rc.tempdir_path = str; - - button = fl_get_button(dialog_->check_last_files); - str = fl_get_input(dialog_->input_lastfiles); + int button = fl_get_button(dialog_->check_last_files); + string str = fl_get_input(dialog_->input_lastfiles); if (!button) str.erase(); rc.check_lastfiles = button; @@ -1880,7 +1882,6 @@ void FormPreferences::Paths::build() setPrehandler(dialog_->input_backup_path); setPrehandler(dialog_->input_serverpipe); setPrehandler(dialog_->input_temp_dir); - setPrehandler(dialog_->check_use_temp_dir); } @@ -1891,8 +1892,6 @@ FormPreferences::Paths::feedback(FL_OBJE return LyXRC::getDescription(LyXRC::RC_DOCUMENTPATH); if (ob == dialog_->input_template_path) return LyXRC::getDescription(LyXRC::RC_TEMPLATEPATH); - if (ob == dialog_->check_use_temp_dir) - return LyXRC::getDescription(LyXRC::RC_USETEMPDIR); if (ob == dialog_->input_temp_dir) return LyXRC::getDescription(LyXRC::RC_TEMPDIRPATH); if (ob == dialog_->check_last_files) @@ -1918,11 +1917,6 @@ bool FormPreferences::Paths::input(FL_OB // !ob if function is called from Paths::update() to de/activate // objects, // otherwise the function is called by an xforms CB via input(). - if (!ob || ob == dialog_->check_use_temp_dir) { - bool const enable = fl_get_button(dialog_->check_use_temp_dir); - setEnabled(dialog_->input_temp_dir, enable); - } - if (!ob || ob == dialog_->check_last_files) { bool const enable = fl_get_button(dialog_->check_last_files); setEnabled(dialog_->input_lastfiles, enable); @@ -2046,13 +2040,7 @@ void FormPreferences::Paths::update(LyXR rc.make_backup); fl_set_input(dialog_->input_backup_path, str.c_str()); - str.erase(); - if (rc.use_tempdir) - str = rc.tempdir_path; - - fl_set_button(dialog_->check_use_temp_dir, - rc.use_tempdir); - fl_set_input(dialog_->input_temp_dir, str.c_str()); + fl_set_input(dialog_->input_temp_dir, rc.tempdir_path.c_str()); str.erase(); if (rc.check_lastfiles) Index: src/frontends/xforms/forms/form_preferences.fd =================================================================== RCS file: /cvs/lyx/lyx-devel/src/frontends/xforms/forms/form_preferences.fd,v retrieving revision 1.62 diff -u -p -r1.62 form_preferences.fd --- src/frontends/xforms/forms/form_preferences.fd 2003/07/23 15:36:40 1.62 +++ src/frontends/xforms/forms/form_preferences.fd 2004/02/15 20:01:21 @@ -2024,7 +2042,7 @@ argument: 0 Name: form_preferences_paths Width: 450 Height: 350 -Number of Objects: 17 +Number of Objects: 16 -------------------- class: FL_BOX @@ -2117,25 +2135,6 @@ callback: C_FormBaseInputCB argument: 0 -------------------- -class: FL_CHECKBUTTON -type: PUSH_BUTTON -box: 140 80 30 30 -boxtype: FL_NO_BOX -colors: FL_COL1 FL_YELLOW -alignment: FL_ALIGN_LEFT -style: FL_NORMAL_STYLE -size: FL_NORMAL_SIZE -lcol: FL_BLACK -label: Temp dir:|#d -shortcut: -resize: FL_RESIZE_ALL -gravity: FL_NoGravity FL_NoGravity -name: check_use_temp_dir -callback: C_FormBaseInputCB -argument: 0 - value: 1 - --------------------- class: FL_INPUT type: NORMAL_INPUT box: 170 80 170 30 @@ -2145,7 +2144,7 @@ alignment: FL_ALIGN_LEFT style: FL_NORMAL_STYLE size: FL_NORMAL_SIZE lcol: FL_BLACK -label: +label: Temp dir:|#d shortcut: resize: FL_RESIZE_ALL gravity: FL_NoGravity FL_NoGravity Index: src/graphics/ChangeLog =================================================================== RCS file: /cvs/lyx/lyx-devel/src/graphics/ChangeLog,v retrieving revision 1.199 diff -u -p -r1.199 ChangeLog --- src/graphics/ChangeLog 2004/01/31 15:30:23 1.199 +++ src/graphics/ChangeLog 2004/02/15 20:01:30 @@ -1,3 +1,10 @@ +2004-02-15 Georg Baum <[EMAIL PROTECTED]> + + * GraphicsCacheItem.C (convertToDisplayFormat): unzip zipped files + to a temporary file + * PreviewLoader.C: use always a tempdir + * PreviewLoader.C: check successfull creation of LaTeX file + 2004-01-31 Lars Gullik Bjonnes <[EMAIL PROTECTED]> * PreviewLoader.C (FindFirst): inherit from std::unary_function Index: src/graphics/GraphicsCacheItem.C =================================================================== RCS file: /cvs/lyx/lyx-devel/src/graphics/GraphicsCacheItem.C,v retrieving revision 1.60 diff -u -p -r1.60 GraphicsCacheItem.C --- src/graphics/GraphicsCacheItem.C 2003/10/06 15:42:58 1.60 +++ src/graphics/GraphicsCacheItem.C 2004/02/15 20:01:30 @@ -35,6 +35,7 @@ using support::OnlyFilename; using support::getExtFromContents; using support::tempName; using support::unlink; +using support::unzippedFileName; using support::unzipFile; using support::zippedFile; @@ -381,8 +382,19 @@ void CacheItem::Impl::convertToDisplayFo } // Make a local copy in case we unzip it - string const filename = zippedFile(filename_) ? - unzipFile(filename_) : filename_; + string filename; + if ((zipped_ = zippedFile(filename_))) { + unzipped_filename_ = tempName(string(), filename_); + if (unzipped_filename_.empty()) { + setStatus(ErrorConverting); + lyxerr[Debug::GRAPHICS] + << "\tCould not create temporary file." << endl; + return; + } + filename = unzipFile(filename_, unzipped_filename_); + } else + filename = filename_; + string const displayed_filename = MakeDisplayPath(filename_); lyxerr[Debug::GRAPHICS] << "[GrahicsCacheItem::convertToDisplayFormat]\n" << "\tAttempting to convert image file: " << filename @@ -412,6 +424,7 @@ void CacheItem::Impl::convertToDisplayFo remove_loaded_file_ = true; // Remove the temp file, we only want the name... + // FIXME: This is unsafe! unlink(to_file_base); // Connect a signal to this->imageConverted and pass this signal to Index: src/graphics/PreviewLoader.C =================================================================== RCS file: /cvs/lyx/lyx-devel/src/graphics/PreviewLoader.C,v retrieving revision 1.73 diff -u -p -r1.73 PreviewLoader.C --- src/graphics/PreviewLoader.C 2004/01/31 15:30:23 1.73 +++ src/graphics/PreviewLoader.C 2004/02/15 20:01:30 @@ -461,8 +461,7 @@ void PreviewLoader::Impl::startLoading() lyxerr[Debug::GRAPHICS] << "PreviewLoader::startLoading()" << endl; // As used by the LaTeX file and by the resulting image files - string const directory = buffer_.temppath().empty() ? - buffer_.filePath() : buffer_.temppath(); + string const directory = buffer_.temppath(); string const filename_base(unique_filename(directory)); @@ -477,6 +476,12 @@ void PreviewLoader::Impl::startLoading() string const latexfile = filename_base + ".tex"; ofstream of(latexfile.c_str()); + if (!of) { + lyxerr[Debug::GRAPHICS] << "PreviewLoader::startLoading()\n" + << "Unable to create LaTeX file\n" + << latexfile << endl; + return; + } of << "\\batchmode\n"; dumpPreamble(of); of << "\n\\begin{document}\n"; Index: src/insets/ChangeLog =================================================================== RCS file: /cvs/lyx/lyx-devel/src/insets/ChangeLog,v retrieving revision 1.967 diff -u -p -r1.967 ChangeLog --- src/insets/ChangeLog 2004/02/13 16:22:52 1.967 +++ src/insets/ChangeLog 2004/02/15 20:01:50 @@ -1,3 +1,12 @@ +2004-02-15 Georg Baum <[EMAIL PROTECTED]> + + * insetexternal.C, insetgraphics.C, insetinclude.C: use always a + tmpdir + * insetinclude.C (latex): show a GUI warning if textclasses don't + match + * insetinclude.C: use mangledFilename() for temp files + * insetgraphics.C (readInsetGraphics): remove version check, since + the graphics inset has no own fileformat number anymore 2004-02-13 André Pönitz <[EMAIL PROTECTED]> Index: src/insets/insetexternal.C =================================================================== RCS file: /cvs/lyx/lyx-devel/src/insets/insetexternal.C,v retrieving revision 1.141 diff -u -p -r1.141 insetexternal.C --- src/insets/insetexternal.C 2004/01/30 11:41:03 1.141 +++ src/insets/insetexternal.C 2004/02/15 20:01:55 @@ -77,6 +77,7 @@ namespace external { TempName::TempName() { tempname_ = support::tempName(string(), "lyxext"); + // FIXME: This is unsafe support::unlink(tempname_); // must have an extension for the converter code to work correctly. tempname_ += ".tmp"; @@ -686,8 +687,7 @@ int InsetExternal::latex(Buffer const & // run through the LaTeX compiler. // If we're running through the LaTeX compiler, we should write the // generated files in the bufer's temporary directory. - bool const external_in_tmpdir = - lyxrc.use_tempdir && !buf.temppath().empty() && !runparams.nice; + bool const external_in_tmpdir = !runparams.nice; // If the template has specified a PDFLaTeX output, then we try and // use that. Index: src/insets/insetgraphics.C =================================================================== RCS file: /cvs/lyx/lyx-devel/src/insets/insetgraphics.C,v retrieving revision 1.235 diff -u -p -r1.235 insetgraphics.C --- src/insets/insetgraphics.C 2004/01/30 11:41:03 1.235 +++ src/insets/insetgraphics.C 2004/02/15 20:01:57 @@ -29,9 +29,6 @@ TODO /* NOTES: * Fileformat: - * Current version is 1 (inset file format version), when changing it - * it should be changed in the Write() function when writing in one place - * and when reading one should change the version check and the error message. * The filename is kept in the lyx file in a relative way, so as to allow * moving the document file and its images with no problem. * @@ -281,18 +278,7 @@ void InsetGraphics::readInsetGraphics(Ly continue; } else if (token == "\\end_inset") { finished = true; - } else if (token == "FormatVersion") { - lex.next(); - int version = lex.getInteger(); - if (version > VersionNumber) - lyxerr - << "This document was created with a newer Graphics widget" - ", You should use a newer version of LyX to read this" - " file." - << endl; - // TODO: Possibly open up a dialog? - } - else { + } else { if (!params_.Read(lex, token, bufpath)) lyxerr << "Unknown token, " << token << ", skipping." << std::endl; @@ -469,9 +455,6 @@ string const InsetGraphics::prepareFile( lyxerr[Debug::GRAPHICS] << "\t we have: from " << from << " to " << to << '\n'; - if (from == to && !lyxrc.use_tempdir) - return stripExtensionIfPossible(orig_file, to); - // We're going to be running the exported buffer through the LaTeX // compiler, so must ensure that LaTeX can cope with the graphics // file format. @@ -480,16 +463,14 @@ string const InsetGraphics::prepareFile( << "\tthe orig file is: " << orig_file << endl; bool conversion_needed = true; - if (lyxrc.use_tempdir) { - CopyStatus status; - boost::tie(status, temp_file) = + CopyStatus status; + boost::tie(status, temp_file) = copyToDirIfNeeded(orig_file, buf.temppath()); - if (status == FAILURE) - return orig_file; - else if (status == IDENTICAL_CONTENTS) - conversion_needed = false; - } + if (status == FAILURE) + return orig_file; + else if (status == IDENTICAL_CONTENTS) + conversion_needed = false; if (from == to) return stripExtensionIfPossible(temp_file, to); @@ -515,7 +496,7 @@ string const InsetGraphics::prepareFile( << "\tto_file_base = " << to_file_base << '\n' << "\t from " << from << " to " << to << '\n'; - // if no special converter defined, than we take the default one + // if no special converter defined, then we take the default one // from ImageMagic: convert from:inname.from to:outname.to if (!converters.convert(&buf, temp_file, to_file_base, from, to)) { string const command = Index: src/insets/insetinclude.C =================================================================== RCS file: /cvs/lyx/lyx-devel/src/insets/insetinclude.C,v retrieving revision 1.182 diff -u -p -r1.182 insetinclude.C --- src/insets/insetinclude.C 2004/01/30 11:41:03 1.182 +++ src/insets/insetinclude.C 2004/02/15 20:01:59 @@ -28,6 +28,7 @@ #include "metricsinfo.h" #include "outputparams.h" +#include "frontends/Alert.h" #include "frontends/LyXView.h" #include "frontends/Painter.h" @@ -36,6 +37,7 @@ #include "insets/render_preview.h" #include "support/FileInfo.h" +#include "support/filename.h" #include "support/filetools.h" #include "support/lstrings.h" // contains #include "support/tostr.h" @@ -46,9 +48,11 @@ #include "support/std_sstream.h" using lyx::support::AddName; +using lyx::support::bformat; using lyx::support::ChangeExtension; using lyx::support::contains; using lyx::support::FileInfo; +using lyx::support::FileName; using lyx::support::GetFileContents; using lyx::support::IsFileReadable; using lyx::support::IsLyXFilename; @@ -307,30 +311,25 @@ int InsetInclude::latex(Buffer const & b if (loadIfNeeded(buffer, params_)) { Buffer * tmp = bufferlist.getBuffer(included_file); - // FIXME: this should be a GUI warning if (tmp->params().textclass != buffer.params().textclass) { - lyxerr << "WARNING: Included file `" - << MakeDisplayPath(included_file) - << "' has textclass `" - << tmp->params().getLyXTextClass().name() - << "' while parent file has textclass `" - << buffer.params().getLyXTextClass().name() - << "'." << endl; + string text = bformat(_("Included file `%1$s'\n" + "has textclass `%2$s'\n" + "while parent file has textclass `%3$s'."), + MakeDisplayPath(included_file), + tmp->params().getLyXTextClass().name(), + buffer.params().getLyXTextClass().name()); + Alert::warning(_("Different textclasses"), text); //return 0; } // write it to a file (so far the complete file) string writefile = ChangeExtension(included_file, ".tex"); - if (!buffer.temppath().empty() && !runparams.nice) { - incfile = subst(incfile, '/','@'); -#ifdef __EMX__ - incfile = subst(incfile, ':', '$'); -#endif - writefile = AddName(buffer.temppath(), incfile); - } else - writefile = included_file; - writefile = ChangeExtension(writefile, ".tex"); + if (!runparams.nice) { + incfile = FileName(writefile).mangledFilename(); + writefile = MakeAbsPath(incfile, buffer.temppath()); + } + lyxerr[Debug::LATEX] << "incfile:" << incfile << endl; lyxerr[Debug::LATEX] << "writefile:" << writefile << endl; @@ -388,15 +387,16 @@ int InsetInclude::linuxdoc(Buffer const Buffer * tmp = bufferlist.getBuffer(included_file); // write it to a file (so far the complete file) - string writefile = ChangeExtension(included_file, ".sgml"); - if (!buffer.temppath().empty() && !runparams.nice) { - incfile = subst(incfile, '/','@'); - writefile = AddName(buffer.temppath(), incfile); - } else + string writefile; + if (IsLyXFilename(included_file)) + writefile = ChangeExtension(included_file, ".sgml"); + else writefile = included_file; - if (IsLyXFilename(included_file)) - writefile = ChangeExtension(writefile, ".sgml"); + if (!runparams.nice) { + incfile = FileName(writefile).mangledFilename(); + writefile = MakeAbsPath(incfile, buffer.temppath()); + } lyxerr[Debug::LATEX] << "incfile:" << incfile << endl; lyxerr[Debug::LATEX] << "writefile:" << writefile << endl; @@ -431,14 +431,16 @@ int InsetInclude::docbook(Buffer const & Buffer * tmp = bufferlist.getBuffer(included_file); // write it to a file (so far the complete file) - string writefile = ChangeExtension(included_file, ".sgml"); - if (!buffer.temppath().empty() && !runparams.nice) { - incfile = subst(incfile, '/','@'); - writefile = AddName(buffer.temppath(), incfile); - } else - writefile = included_file; + string writefile; if (IsLyXFilename(included_file)) - writefile = ChangeExtension(writefile, ".sgml"); + writefile = ChangeExtension(included_file, ".sgml"); + else + writefile = included_file; + + if (!runparams.nice) { + incfile = FileName(writefile).mangledFilename(); + writefile = MakeAbsPath(incfile, buffer.temppath()); + } lyxerr[Debug::LATEX] << "incfile:" << incfile << endl; lyxerr[Debug::LATEX] << "writefile:" << writefile << endl; @@ -468,18 +470,14 @@ void InsetInclude::validate(LaTeXFeature string const included_file = includedFilename(buffer, params_); if (IsLyXFilename(included_file)) - writefile = ChangeExtension(writefile, ".sgml"); - else if (!buffer.temppath().empty() && - !features.nice() && - !isVerbatim(params_)) { - incfile = subst(incfile, '/','@'); -#ifdef __EMX__ -// FIXME: It seems that the following is necessary (see latex() above) -// incfile = subst(incfile, ':', '$'); -#endif - writefile = AddName(buffer.temppath(), incfile); - } else + writefile = ChangeExtension(included_file, ".sgml"); + else writefile = included_file; + + if (!features.nice() && !isVerbatim(params_)) { + incfile = FileName(writefile).mangledFilename(); + writefile = MakeAbsPath(incfile, buffer.temppath()); + } features.includeFile(include_label, writefile); Index: src/support/ChangeLog =================================================================== RCS file: /cvs/lyx/lyx-devel/src/support/ChangeLog,v retrieving revision 1.237 diff -u -p -r1.237 ChangeLog --- src/support/ChangeLog 2004/02/01 12:46:13 1.237 +++ src/support/ChangeLog 2004/02/15 20:02:16 @@ -1,3 +1,11 @@ +2004-02-15 Georg Baum <[EMAIL PROTECTED]> + + * filetools.[Ch] (CreateBufferTmpDir): rename to createBufferTmpDir, + remove pathfor argument + * filetools.[Ch] (CreateLyXTmpDir): rename to createLyXTmpDir, try + harder to create a usable temp dir + * filetools.C (CreateTmpDir): rename to createTmpDir + 2004-02-01 Lars Gullik Bjonnes <[EMAIL PROTECTED]> * lstrings.h (contains_functor): delete Index: src/support/filetools.C =================================================================== RCS file: /cvs/lyx/lyx-devel/src/support/filetools.C,v retrieving revision 1.176 diff -u -p -r1.176 filetools.C --- src/support/filetools.C 2003/10/16 16:41:32 1.176 +++ src/support/filetools.C 2004/02/15 20:02:20 @@ -440,11 +440,11 @@ int DeleteAllFilesInDir(string const & p } -string const CreateTmpDir(string const & tempdir, string const & mask) +string const createTmpDir(string const & tempdir, string const & mask) { lyxerr[Debug::FILES] - << "CreateTmpDir: tempdir=`" << tempdir << "'\n" - << "CreateTmpDir: mask=`" << mask << '\'' << endl; + << "createTmpDir: tempdir=`" << tempdir << "'\n" + << "createTmpDir: mask=`" << mask << '\'' << endl; string const tmpfl(tempName(tempdir, mask)); // lyx::tempName actually creates a file to make sure that it @@ -453,8 +453,11 @@ string const CreateTmpDir(string const & // safe because of the gap between unlink and mkdir. (Lgb) unlink(tmpfl); - if (tmpfl.empty() || mkdir(tmpfl, 0700)) + if (tmpfl.empty() || mkdir(tmpfl, 0700)) { + lyxerr << "LyX could not create the temporary directory '" + << tmpfl << "'" << endl; return string(); + } return MakeAbsPath(tmpfl); } @@ -477,36 +480,47 @@ int destroyDir(string const & tmpdir) } -string const CreateBufferTmpDir(string const & pathfor) +string const createBufferTmpDir() { static int count; - static string const tmpdir(pathfor.empty() ? os::getTmpDir() : pathfor); // We are in our own directory. Why bother to mangle name? // In fact I wrote this code to circumvent a problematic behaviour (bug?) // of EMX mkstemp(). - string const tmpfl = tmpdir + "/lyx_tmpbuf" + tostr(count++); + string const tmpfl = os::getTmpDir() + "/lyx_tmpbuf" + tostr(count++); if (mkdir(tmpfl, 0777)) { + lyxerr << "LyX could not create the temporary directory '" + << tmpfl << "'" << endl; return string(); } return tmpfl; } -string const CreateLyXTmpDir(string const & deflt) +string const createLyXTmpDir(string const & deflt) { - if ((!deflt.empty()) && (deflt != "/tmp")) { + if (!deflt.empty() && deflt != "/tmp") { if (mkdir(deflt, 0777)) { + if (IsDirWriteable(deflt)) + // deflt could not be created because it + // did exist already, so let's create our own + // dir inside deflt. #ifdef __EMX__ - Path p(user_lyxdir()); + Path p(user_lyxdir()); +#endif + return createTmpDir(deflt, "lyx_tmpdir"); + else + // some other error occured. +#ifdef __EMX__ + Path p(user_lyxdir()); #endif - return CreateTmpDir(deflt, "lyx_tmpdir"); + return createTmpDir("/tmp", "lyx_tmpdir"); } else return deflt; } else { #ifdef __EMX__ Path p(user_lyxdir()); #endif - return CreateTmpDir("/tmp", "lyx_tmpdir"); + return createTmpDir("/tmp", "lyx_tmpdir"); } } @@ -1080,9 +1094,10 @@ string const unzippedFileName(string con } -string const unzipFile(string const & zipped_file) +string const unzipFile(string const & zipped_file, string const & unzipped_file) { - string const tempfile = unzippedFileName(zipped_file); + string const tempfile = unzipped_file.empty() ? + unzippedFileName(zipped_file) : unzipped_file; // Run gunzip string const command = "gunzip -c " + zipped_file + " > " + tempfile; Systemcall one; Index: src/support/filetools.h =================================================================== RCS file: /cvs/lyx/lyx-devel/src/support/filetools.h,v retrieving revision 1.53 diff -u -p -r1.53 filetools.h --- src/support/filetools.h 2003/10/06 15:43:18 1.53 +++ src/support/filetools.h 2004/02/15 20:02:21 @@ -22,14 +22,19 @@ namespace support { /// remove directory and all contents, returns 0 on success int destroyDir(std::string const & tmpdir); -/// -std::string const CreateBufferTmpDir(std::string const & pathfor = std::string()); +/// Creates the per buffer temporary directory +std::string const createBufferTmpDir(); /// Creates directory. Returns true on success bool createDirectory(std::string const & name, int permissions); -/// -std::string const CreateLyXTmpDir(std::string const & deflt); +/** Creates the global LyX temp dir. + \p deflt can be an existing directory name. In this case a new directory + inside \p deflt is created. If \p deflt does not exist yet, \p deflt is + created and used as the temporary directory. + \return the tmp dir name or string() if something went wrong. + */ +std::string const createLyXTmpDir(std::string const & deflt); /** Find file by searching several directories. Uses a string of paths separated by ";"s to find a file to open. @@ -141,11 +146,18 @@ std::string const getExtFromContents(std /// check for zipped file bool zippedFile(std::string const & name); -/// \return the name that LyX will give to the unzipped file. +/** \return the name that LyX will give to the unzipped file \p zipped_file + if the second argument of unzipFile() is empty. + */ std::string const unzippedFileName(std::string const & zipped_file); -/// unzip a file -std::string const unzipFile(std::string const & zipped_file); +/** Unzip \p zipped_file. + The unzipped file is named \p unzipped_file if \p unzipped_file is not + empty, and unzippedFileName(\p zipped_file) otherwise. + Will overwrite an already existing unzipped file without warning. + */ +std::string const unzipFile(std::string const & zipped_file, + std::string const & unzipped_file = std::string()); /// Returns true is path is absolute bool AbsolutePath(std::string const & path);