From a3c0b049bf4fabee1b7b4ab3a5513dc11c5e9dd4 Mon Sep 17 00:00:00 2001 From: Mathias Gumz Date: Fri, 2 Jan 2015 17:04:36 +0100 Subject: [PATCH] Fix corruption of fbrun-history This commit fixes issues #72 (brought up + different solution by Mattias Guns; I received a similar patch by 'Nable 80' via ML and discussed the issue in #fluxbox with 'Nable 80'), patch #73 (Mattias Guns) and finally patch #162 (Ulrich Eckhardt; this commit is heavily based upon Ulrich's work). The original code was overly complex. It tried to avoid writing bytes to the disk at the expense of comprehensibility and as a result it was buggy. I looked at both patches from Mattias and 'Nable 80' which address the bug with skipping entries in the history-file (my fault: incorrect use of outfile.ignore(1, '\n')): They provided a proper fix for the problem but I decided to use Ulrich's code since it improves the whole code by making it a lot simpler. So, kudos to all of you. --- util/fbrun/FbRun.cc | 64 +++++++++++++++------------------------------ 1 file changed, 21 insertions(+), 43 deletions(-) diff --git a/util/fbrun/FbRun.cc b/util/fbrun/FbRun.cc index a8584878..8cc6b161 100644 --- a/util/fbrun/FbRun.cc +++ b/util/fbrun/FbRun.cc @@ -110,12 +110,18 @@ FbRun::~FbRun() { } void FbRun::run(const std::string &command) { + FbTk::App::instance()->end(); // end application m_end = true; // mark end of processing + hide(); // hide gui + if (m_print) { std::cout << command; - hide(); + return; + } + + if (command.empty()) { return; } @@ -152,52 +158,24 @@ void FbRun::run(const std::string &command) { #error "Can't build FbRun - don't know how to launch without fork on your platform" #endif - hide(); // hide gui - - // save command history to file - if (text().size() != 0) { // no need to save empty command - - // don't allow duplicates into the history file, first - // look for a duplicate - if (m_current_history_item < m_history.size() - && text() == m_history[m_current_history_item]) { - // m_current_history_item is the duplicate - } else { - m_current_history_item = 0; - for (; m_current_history_item < m_history.size(); - ++m_current_history_item) { - if (m_history[m_current_history_item] == text()) - break; - } - } - - fstream inoutfile(m_history_file.c_str(), ios::in|ios::out); - if (inoutfile) { - // now m_current_history_item points at the duplicate, or - // at m_history.size() if no duplicate - if (m_current_history_item != m_history.size()) { - unsigned int i = 0; - // read past history items before current - for (; inoutfile.good() && i < m_current_history_item; i++) - inoutfile.ignore(1, '\n'); - - // write the history items that come after current - for (i++; i < m_history.size(); i++) - inoutfile<