From: Kern Sibbald Date: Wed, 21 Feb 2007 20:07:37 +0000 (+0000) Subject: Start restore tree X-Git-Tag: Release-7.0.0~6851 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=a5611b763e9957246a1ecb1830e44409ccbfd794;p=bacula%2Fbacula Start restore tree git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@4230 91ce42f0-d328-0410-95d8-f526ca767f89 --- diff --git a/bacula/src/qt-console/console/console.cpp b/bacula/src/qt-console/console/console.cpp index 9048774c5b..60a230a57d 100644 --- a/bacula/src/qt-console/console/console.cpp +++ b/bacula/src/qt-console/console/console.cpp @@ -104,17 +104,17 @@ void Console::connect() m_textEdit = textEdit; /* our console screen */ if (!m_dir) { - mainWin->set_status(" No Director found."); + mainWin->set_status("No Director found."); return; } if (m_sock) { - mainWin->set_status(" Already connected."); + mainWin->set_status("Already connected."); return; } memset(&jcr, 0, sizeof(jcr)); - mainWin->set_statusf(_(" Connecting to Director %s:%d"), m_dir->address, m_dir->DIRport); + mainWin->set_statusf(_("Connecting to Director %s:%d"), m_dir->address, m_dir->DIRport); display_textf(_("Connecting to Director %s:%d\n\n"), m_dir->address, m_dir->DIRport); /* Give GUI a chance */ @@ -147,12 +147,13 @@ void Console::connect() /* Give GUI a chance */ app->processEvents(); - mainWin->set_status(_(" Initializing ...")); + mainWin->set_status(_("Initializing ...")); /* Set up input notifier */ m_notifier = new QSocketNotifier(m_sock->fd, QSocketNotifier::Read, 0); QObject::connect(m_notifier, SIGNAL(activated(int)), this, SLOT(read_dir(int))); + beginNewCommand(); job_list = get_list(".jobs"); client_list = get_list(".clients"); fileset_list = get_list(".filesets"); @@ -162,7 +163,7 @@ void Console::connect() type_list = get_list(".types"); level_list = get_list(".levels"); - mainWin->set_status(_(" Connected")); + mainWin->set_status(_("Connected")); return; } @@ -193,13 +194,15 @@ QStringList Console::get_list(char *cmd) */ bool Console::get_job_defaults(struct job_defaults &job_defs) { + QString scmd; char cmd[1000]; int stat; char *def; setEnabled(false); - bsnprintf(cmd, sizeof(cmd), ".defaults job=\"%s\"", job_defs.job_name.toUtf8().data()); - write(cmd); + beginNewCommand(); + scmd = QString(".defaults job=\"%1\"").arg(job_defs.job_name); + write(scmd); while ((stat = read()) > 0) { def = strchr(msg(), '='); if (!def) { @@ -384,11 +387,11 @@ void Console::write_dir(const char *msg) { if (m_sock) { m_at_prompt = false; - mainWin->set_status(_(" Processing command ...")); + mainWin->set_status(_("Processing command ...")); QApplication::setOverrideCursor(Qt::WaitCursor); m_sock->msglen = strlen(msg); pm_strcpy(&m_sock->msg, msg); - bnet_send(m_sock); + m_sock->send(); } else { mainWin->set_status(" Director not connected. Click on connect button."); mainWin->actionConnect->setIcon(QIcon(QString::fromUtf8("images/disconnected.png"))); @@ -397,11 +400,42 @@ void Console::write_dir(const char *msg) } } +int Console::write(const QString msg) +{ + return write(msg.toUtf8().data()); +} + int Console::write(const char *msg) { m_sock->msglen = strlen(msg); pm_strcpy(&m_sock->msg, msg); - return bnet_send(m_sock); + return m_sock->send(); +} + +/* + * Get to main command prompt + */ +void Console::beginNewCommand() +{ +// displayToPrompt(); + write(".\n"); + while (read() > 0) { + } + write(".\n"); + while (read() > 0) { + } + write(".\n"); + while (read() > 0) { + } + display_text("\n"); +} + +void Console::displayToPrompt() +{ + while (read() > 0) { + display_text(msg()); + } + } /* @@ -420,7 +454,7 @@ int Console::read() return BNET_ERROR; } } - return bnet_recv(m_sock); + return m_sock->recv(); } return BNET_HARDEOF; } @@ -434,13 +468,13 @@ void Console::read_dir(int fd) if (!m_sock) { return; } - stat = bnet_recv(m_sock); + stat = read(); if (stat >= 0) { if (m_at_prompt) { display_text("\n"); m_at_prompt = false; } - display_text(m_sock->msg); + display_text(msg()); return; } if (is_bnet_stop(m_sock)) { /* error or term request */ @@ -452,14 +486,14 @@ void Console::read_dir(int fd) m_notifier->setEnabled(false); delete m_notifier; m_notifier = NULL; - mainWin->set_status(_(" Director disconnected.")); + mainWin->set_status(_("Director disconnected.")); QApplication::restoreOverrideCursor(); return; } /* Must be a signal -- either do something or ignore it */ if (m_sock->msglen == BNET_PROMPT) { m_at_prompt = true; - mainWin->set_status(_(" At prompt waiting for input ...")); + mainWin->set_status(_("At prompt waiting for input ...")); update_cursor(); } if (m_sock->msglen == BNET_EOD) { diff --git a/bacula/src/qt-console/console/console.h b/bacula/src/qt-console/console/console.h index be9509cee4..2c66a2b68a 100644 --- a/bacula/src/qt-console/console/console.h +++ b/bacula/src/qt-console/console/console.h @@ -56,17 +56,6 @@ struct job_defaults { QString type; QString fileset_name; QString catalog_name; -#ifdef xxx - char pool_name[MAX_NAME_LENGTH]; - char messages_name[MAX_NAME_LENGTH]; - char client_name[MAX_NAME_LENGTH]; - char store_name[MAX_NAME_LENGTH]; - char where[MAX_NAME_LENGTH]; - char level[MAX_NAME_LENGTH]; - char type[MAX_NAME_LENGTH]; - char fileset_name[MAX_NAME_LENGTH]; - char catalog_name[MAX_NAME_LENGTH]; -#endif bool enabled; }; @@ -96,6 +85,8 @@ public: QStringList get_list(char *cmd); bool get_job_defaults(struct job_defaults &); void terminate(); + void beginNewCommand(); + void displayToPrompt(); QStringList job_list; QStringList client_list; @@ -111,6 +102,7 @@ public slots: void read_dir(int fd); int read(void); int write(const char *msg); + int write(QString msg); void status_dir(void); void set_font(void); diff --git a/bacula/src/qt-console/restore/restore.cpp b/bacula/src/qt-console/restore/restore.cpp index f37891d1fb..fececa06c2 100644 --- a/bacula/src/qt-console/restore/restore.cpp +++ b/bacula/src/qt-console/restore/restore.cpp @@ -38,12 +38,6 @@ #include "bat.h" #include "restore.h" -restoreDialog::restoreDialog(Console *parent) -{ - (void)parent; /* keep compiler quiet */ - setupUi(this); - this->show(); -} prerestoreDialog::prerestoreDialog(Console *console) { @@ -74,9 +68,10 @@ void prerestoreDialog::accept() .arg(poolCombo->currentText()) .arg(storageCombo->currentText()); -// m_console->write(cmd); + m_console->write(cmd); m_console->display_text(cmd); delete this; + new restoreDialog(m_console); } @@ -101,3 +96,99 @@ void prerestoreDialog::job_name_change(int index) storageCombo->setCurrentIndex(storageCombo->findText(job_defs.store_name, Qt::MatchExactly)); } } + +restoreDialog::restoreDialog(Console *console) +{ + m_console = console; + setupUi(this); + fillDirectory("/"); + this->show(); +} + +/* + * Fill the CList box with files at path + */ +void restoreDialog::fillDirectory(const char *path) +{ + char pathbuf[MAXSTRING]; + char modes[20], user[20], group[20], size[20], date[30]; + char file[1000]; + char marked[10]; + int row = 0; + + m_console->setEnabled(false); + m_fname = path; + + + m_console->displayToPrompt(); + bsnprintf(pathbuf, sizeof(pathbuf), "cd %s", path); + Dmsg1(100, "%s\n", pathbuf); + + m_console->write(pathbuf); + m_console->display_text(pathbuf); + m_console->displayToPrompt(); + + m_console-> write_dir("dir"); + m_console->display_text("dir"); + while (m_console->read() > 0) { + char *p = m_console->msg(); + char *l; + strip_trailing_junk(p); + if (*p == '$') { + break; + } + Dmsg1(200, "Got: %s\n", p); + if (!*p) { + continue; + } + l = p; + skip_nonspaces(&p); /* permissions */ + *p++ = 0; + bstrncpy(modes, l, sizeof(modes)); + skip_spaces(&p); + skip_nonspaces(&p); /* link count */ + *p++ = 0; + skip_spaces(&p); + l = p; + skip_nonspaces(&p); /* user */ + *p++ = 0; + skip_spaces(&p); + bstrncpy(user, l, sizeof(user)); + l = p; + skip_nonspaces(&p); /* group */ + *p++ = 0; + bstrncpy(group, l, sizeof(group)); + skip_spaces(&p); + l = p; + skip_nonspaces(&p); /* size */ + *p++ = 0; + bstrncpy(size, l, sizeof(size)); + skip_spaces(&p); + l = p; + skip_nonspaces(&p); /* date/time */ + skip_spaces(&p); + skip_nonspaces(&p); + *p++ = 0; + bstrncpy(date, l, sizeof(date)); + skip_spaces(&p); + if (*p == '*') { + bstrncpy(marked, "x", sizeof(marked)); + p++; + } else { + bstrncpy(marked, " ", sizeof(marked)); + } +// split_path_and_filename(p, &restore->path, &restore->pnl, +// &restore->file, &restore->fnl); + +// Dmsg1(000, "restore->fname=%s\n", restore->fname); +// bstrncpy(file, restore->file, sizeof(file)); + printf("modes=%s user=%s group=%s size=%s date=%s file=%s\n", + modes, user, group, size, date, file); + +// append to list + + row++; + } + + m_console->setEnabled(true); +} diff --git a/bacula/src/qt-console/restore/restore.h b/bacula/src/qt-console/restore/restore.h index d5823d6d62..1f5be13ded 100644 --- a/bacula/src/qt-console/restore/restore.h +++ b/bacula/src/qt-console/restore/restore.h @@ -64,11 +64,13 @@ class restoreDialog : public QDialog, public Ui::restoreForm public: restoreDialog(Console *parent); + void fillDirectory(const char *path); public slots: - private: + Console *m_console; + QString m_fname; }; diff --git a/bacula/src/qt-console/run/run.cpp b/bacula/src/qt-console/run/run.cpp index 82f1f2257b..8eaa1407ce 100644 --- a/bacula/src/qt-console/run/run.cpp +++ b/bacula/src/qt-console/run/run.cpp @@ -42,6 +42,7 @@ runDialog::runDialog(Console *console) m_console = console; setupUi(this); + m_console->beginNewCommand(); jobCombo->addItems(console->job_list); filesetCombo->addItems(console->fileset_list); levelCombo->addItems(console->level_list); @@ -98,9 +99,7 @@ void runDialog::job_name_change(int index) clientCombo->setCurrentIndex(clientCombo->findText(job_defs.client_name, Qt::MatchExactly)); poolCombo->setCurrentIndex(poolCombo->findText(job_defs.pool_name, Qt::MatchExactly)); storageCombo->setCurrentIndex(storageCombo->findText(job_defs.store_name, Qt::MatchExactly)); - while (typeCombo->count() > 0) { - typeCombo->removeItem(0); - } + typeCombo->clear(); typeCombo->addItem(job_defs.type); } }