aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFritz Elfert <felfert@to.com>2001-04-08 22:38:29 +0000
committerFritz Elfert <felfert@to.com>2001-04-08 22:38:29 +0000
commit11258129a00f5faa744465706dfe334a44ae3b52 (patch)
tree97c9bf0ac38f7c6546ec44fcb5668d7e7ec63058
parentf7d131f1eb3c950e1c0315854f10da89d57353de (diff)
downloadplptools-11258129a00f5faa744465706dfe334a44ae3b52.tar.gz
plptools-11258129a00f5faa744465706dfe334a44ae3b52.tar.bz2
plptools-11258129a00f5faa744465706dfe334a44ae3b52.zip
Implemented ncpd autostart and removing of old backup generations.
-rw-r--r--kde2/kpsion/kpsion.cpp162
-rw-r--r--kde2/kpsion/kpsion.h5
-rw-r--r--kde2/kpsion/kpsionconfig.cpp2
-rw-r--r--kde2/kpsion/kpsionconfig.h2
-rw-r--r--lib/rfsv.cc1
5 files changed, 162 insertions, 10 deletions
diff --git a/kde2/kpsion/kpsion.cpp b/kde2/kpsion/kpsion.cpp
index 292ed08..01087b6 100644
--- a/kde2/kpsion/kpsion.cpp
+++ b/kde2/kpsion/kpsion.cpp
@@ -37,6 +37,7 @@
#include <kiconview.h>
#include <kmessagebox.h>
#include <kfileitem.h>
+#include <kprocess.h>
#include <qwhatsthis.h>
#include <qtimer.h>
@@ -112,11 +113,15 @@ KPsionMainWindow::KPsionMainWindow()
config->setGroup(pcfg.getSectionName(KPsionConfig::OPT_SERIALDEV));
ncpdDevice = config->readEntry(pcfg.getOptionName(
- KPsionConfig::OPT_SERIALDEV));
+ KPsionConfig::OPT_SERIALDEV), "off");
+
+ config->setGroup(pcfg.getSectionName(KPsionConfig::OPT_NCPDPATH));
+ ncpdPath = config->readEntry(pcfg.getOptionName(
+ KPsionConfig::OPT_NCPDPATH), "ncpd");
config->setGroup(pcfg.getSectionName(KPsionConfig::OPT_SERIALSPEED));
- ncpdSpeed = config->readNumEntry(
- pcfg.getOptionName(KPsionConfig::OPT_SERIALSPEED));
+ ncpdSpeed = config->readEntry(
+ pcfg.getOptionName(KPsionConfig::OPT_SERIALSPEED), "115200");
QWhatsThis::add(view, i18n(
"<qt>Here, you see your Psion's drives.<br/>"
@@ -183,8 +188,6 @@ setupActions() {
actionCollection());
KStdAction::showStatusbar(this, SLOT(slotToggleStatusbar()),
actionCollection());
-// KStdAction::saveOptions(this, SLOT(slotSaveOptions()),
-// actionCollection());
KStdAction::preferences(this, SLOT(slotPreferences()),
actionCollection());
new KAction(i18n("Start &Format"), 0L, 0, this,
@@ -525,6 +528,28 @@ queryClose() {
}
void KPsionMainWindow::
+startupNcpd() {
+ if (ncpdDevice == "off")
+ return;
+ KProcess proc;
+ ppsocket *testSocket;
+
+ testSocket = new ppsocket();
+ if (!testSocket->connect(NULL, 7501)) {
+ time_t start_time = time(0L) + 2;
+
+ statusBar()->changeItem(i18n("Starting ncpd daemon ..."),
+ STID_CONNECTION);
+ proc << ncpdPath;
+ proc << "-s" << ncpdDevice << "-b" << ncpdSpeed;
+ proc.start(KProcess::DontCare);
+ while ((time(0L) < start_time) && (!testSocket->connect(NULL, 7501)))
+ kapp->processEvents();
+ }
+ delete testSocket;
+}
+
+void KPsionMainWindow::
tryConnect() {
if (shuttingDown || connected)
return;
@@ -540,6 +565,7 @@ tryConnect() {
if (rfsvSocket)
delete rpcsSocket;
+ startupNcpd();
rfsvSocket = new ppsocket();
statusBar()->changeItem(i18n("Connecting ..."), STID_CONNECTION);
if (!rfsvSocket->connect(NULL, 7501)) {
@@ -718,6 +744,7 @@ void KPsionMainWindow::
doBackup() {
backupRunning = true;
switchActions();
+ QStringList processDrives;
toBackup.clear();
// Collect list of files to backup
@@ -749,6 +776,7 @@ doBackup() {
progressLocalPercent = -1;
progress->setValue(0);
collectFiles(drv);
+ processDrives += drv;
}
}
emit setProgressText(i18n("%1 files need backup").arg(backupSize));
@@ -765,7 +793,6 @@ doBackup() {
return;
}
- // statusBar()->message(i18n("Backup"));
progressCount = 0;
progressTotal = backupSize;
progressPercent = -1;
@@ -783,7 +810,6 @@ doBackup() {
statusBar()->changeItem(i18n("Connected to %1").arg(machineName),
STID_CONNECTION);
KMessageBox::error(this, i18n("Could not create backup folder %1").arg(archiveName));
- // statusBar()->clear();
backupRunning = false;
switchActions();
return;
@@ -887,13 +913,19 @@ doBackup() {
backupTgz->close();
delete backupTgz;
+ emit enableProgressText(false);
+ emit setProgress(0);
+
if (badBackup)
::unlink(archiveName.latin1());
else {
QString newName = archiveName;
newName.replace(QRegExp("\\.tmp\\.gz$"), ".tar.gz");
// Rename Tarfile to its final name;
- ::rename(archiveName.latin1(), newName.latin1());
+ if (::rename(archiveName.latin1(), newName.latin1()) != 0)
+ KMessageBox::sorry(this, i18n("<QT>Could not rename backup archive from<BR/><B>%1</B> to<BR/><B>%2</B></QT>").arg(archiveName).arg(newName));
+ else
+ removeOldBackups(processDrives);
}
backupRunning = false;
@@ -905,6 +937,120 @@ doBackup() {
statusBar()->message(i18n("Backup done"), 2000);
}
+class Barchive {
+public:
+ Barchive()
+ : n(""), d(0) {}
+ Barchive(const QString &name, time_t date)
+ : n(name), d(date) {}
+
+ QString name() const { return n; }
+ time_t date() const { return d; }
+ bool operator==(const Barchive &a) { return (a.n == n); }
+private:
+ QString n;
+ time_t d;
+};
+
+typedef QValueList<Barchive>ArchList;
+
+void KPsionMainWindow::
+removeOldBackups(QStringList &drives) {
+
+ KConfig *config = kapp->config();
+ KPsionConfig pcfg;
+
+ config->setGroup(pcfg.getSectionName(KPsionConfig::OPT_BACKUPGEN));
+ int bgen = config->readNumEntry(
+ pcfg.getOptionName(KPsionConfig::OPT_BACKUPGEN));
+
+ if (bgen == 0)
+ return;
+
+ statusBar()->changeItem(i18n("Removing old backups ..."), STID_CONNECTION);
+ QString bdir(backupDir);
+ bdir += "/";
+ bdir += getMachineUID();
+ QDir d(bdir);
+ kapp->processEvents();
+ const QFileInfoList *fil =
+ d.entryInfoList("*.tar.gz", QDir::Files|QDir::Readable, QDir::Name);
+ QFileInfoListIterator it(*fil);
+ QFileInfo *fi;
+ ArchList alist;
+ Barchive *a;
+
+ // Build a list of full-backups sorted by date
+ while ((fi = it.current())) {
+ kapp->processEvents();
+
+ KTarGz tgz(fi->absFilePath());
+ const KTarEntry *te;
+
+ tgz.open(IO_ReadOnly);
+ te = tgz.directory()->entry("KPsionFullIndex");
+ if (te && (!te->isDirectory())) {
+ for (QStringList::Iterator d = drives.begin(); d != drives.end();
+ d++) {
+ const KTarEntry *de = tgz.directory()->entry(*d);
+ if (de && (de->isDirectory())) {
+ Barchive a(tgz.fileName(), te->date());
+ if (!alist.contains(a)) {
+ if (alist.isEmpty() || (alist.first().date()>te->date()))
+ alist.prepend(a);
+ else
+ alist.append(a);
+ }
+ }
+ }
+ }
+ tgz.close();
+ ++it;
+ }
+
+ // Remove entries from the beginning of the list if there are more than
+ // bgen entries. This leaves at most bgen of the youngest backups in the
+ // list.
+ while (alist.count() > bgen) {
+ Barchive r = alist.first();
+ alist.remove(r);
+ }
+
+ // Finally iterate over all backups and delete those which are older
+ // than the first entry in alist.
+
+ (void)it.toFirst();
+
+ while ((fi = it.current())) {
+ kapp->processEvents();
+
+ KTarGz tgz(fi->absFilePath());
+ const KTarEntry *te;
+ bool valid = false;
+ bool del = false;
+
+ tgz.open(IO_ReadOnly);
+ te = tgz.directory()->entry("KPsionFullIndex");
+ if (te && (!te->isDirectory()))
+ valid = true;
+ else {
+ te = tgz.directory()->entry("KPsionIncrementalIndex");
+ if (te && (!te->isDirectory()))
+ valid = true;
+ }
+ if (valid) {
+ Barchive a(tgz.fileName(), te->date());
+ if (alist.isEmpty() ||
+ ((!alist.contains(a)) && (te->date() < alist.first().date())))
+ del = true;
+ }
+ tgz.close();
+ if (del)
+ ::remove(fi->absFilePath().data());
+ ++it;
+ }
+}
+
bool KPsionMainWindow::
askOverwrite(PlpDirent e) {
if (overWriteAll)
diff --git a/kde2/kpsion/kpsion.h b/kde2/kpsion/kpsion.h
index 1ec7715..c7832b8 100644
--- a/kde2/kpsion/kpsion.h
+++ b/kde2/kpsion/kpsion.h
@@ -101,6 +101,8 @@ private:
void setDriveName(const char dchar, QString dname);
void doFormat(QString drive);
void updateBackupStamps();
+ void startupNcpd();
+ void removeOldBackups(QStringList &drives);
rfsv *plpRfsv;
rpcs *plpRpcs;
@@ -121,6 +123,8 @@ private:
QString machineName;
QString statusMsg;
QString ncpdDevice;
+ QString ncpdSpeed;
+ QString ncpdPath;
QString progressTotalText;
bool S5mx;
bool backupRunning;
@@ -136,7 +140,6 @@ private:
bool quitImmediately;
int reconnectTime;
int nextTry;
- int ncpdSpeed;
unsigned long long machineUID;
PlpDir toBackup;
unsigned long backupSize;
diff --git a/kde2/kpsion/kpsionconfig.cpp b/kde2/kpsion/kpsionconfig.cpp
index bd08b6d..d6119a0 100644
--- a/kde2/kpsion/kpsionconfig.cpp
+++ b/kde2/kpsion/kpsionconfig.cpp
@@ -36,6 +36,7 @@ KPsionConfig::KPsionConfig() {
optionNames.insert(OPT_CONNRETRY, QString("Connection/Retry"));
optionNames.insert(OPT_SERIALDEV, QString("Connection/Device"));
optionNames.insert(OPT_SERIALSPEED, QString("Connection/Speed"));
+ optionNames.insert(OPT_NCPDPATH, QString("Connection/NcpdPath"));
optionNames.insert(OPT_UIDS, QString("Psion/MachineUIDs"));
optionNames.insert(OPT_MACHNAME, QString("Psion/Name_%1"));
optionNames.insert(OPT_BACKUPDRIVES, QString("Psion/BackupDrives_%1"));
@@ -49,6 +50,7 @@ KPsionConfig::KPsionConfig() {
defaults.insert(DEF_SERIALDEV, QString("0"));
defaults.insert(DEF_SERIALSPEED, QString("4"));
defaults.insert(DEF_BACKUPGEN, QString("3"));
+ defaults.insert(DEF_NCPDPATH, QString("ncpd"));
}
const QString KPsionConfig::
diff --git a/kde2/kpsion/kpsionconfig.h b/kde2/kpsion/kpsionconfig.h
index 1b8de31..2fddf5e 100644
--- a/kde2/kpsion/kpsionconfig.h
+++ b/kde2/kpsion/kpsionconfig.h
@@ -47,6 +47,7 @@ public:
OPT_DRIVES = 10,
OPT_LASTFULL = 11,
OPT_LASTINC = 12,
+ OPT_NCPDPATH = 13,
};
enum cfgDefaults {
@@ -57,6 +58,7 @@ public:
DEF_SERIALDEV = 4,
DEF_SERIALSPEED = 5,
DEF_BACKUPGEN = 6,
+ DEF_NCPDPATH = 13,
};
KPsionConfig();
diff --git a/lib/rfsv.cc b/lib/rfsv.cc
index f9f2075..25bf91c 100644
--- a/lib/rfsv.cc
+++ b/lib/rfsv.cc
@@ -114,7 +114,6 @@ rfsv::~rfsv() {
void rfsv::reconnect(void)
{
- //skt->closeSocket();
skt->reconnect();
serNum = 0;
reset();