summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2004-11-10 14:03:37 (UTC)
committer mickeyl <mickeyl>2004-11-10 14:03:37 (UTC)
commit9088b52d1ef7c4e70e62a53e225c69508cc8afe3 (patch) (unidiff)
tree38ac61c1004edecdec8cf5b1708816e13bb643df
parentfcd9c62650dd1bb9c04bfd798d243cb894a8f393 (diff)
downloadopie-9088b52d1ef7c4e70e62a53e225c69508cc8afe3.zip
opie-9088b52d1ef7c4e70e62a53e225c69508cc8afe3.tar.gz
opie-9088b52d1ef7c4e70e62a53e225c69508cc8afe3.tar.bz2
start working on clone functionality
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/backup/backuprestore.cpp87
1 files changed, 86 insertions, 1 deletions
diff --git a/noncore/settings/backup/backuprestore.cpp b/noncore/settings/backup/backuprestore.cpp
index c944c6d..869c1b8 100644
--- a/noncore/settings/backup/backuprestore.cpp
+++ b/noncore/settings/backup/backuprestore.cpp
@@ -1,84 +1,85 @@
1/* 1/*
2                This file is part of the Opie Project 2                This file is part of the Opie Project
3 =. 3 =.
4             .=l. Copyright (c) 2002-2004 The Opie Team <opie-devel@handhelds.org> 4             .=l. Copyright (c) 2002-2004 The Opie Team <opie-devel@handhelds.org>
5           .>+-= 5           .>+-=
6 _;:,     .>    :=|. This file is free software; you can 6 _;:,     .>    :=|. This file is free software; you can
7.> <`_,   >  .   <= redistribute it and/or modify it under 7.> <`_,   >  .   <= redistribute it and/or modify it under
8:`=1 )Y*s>-.--   : the terms of the GNU General Public 8:`=1 )Y*s>-.--   : the terms of the GNU General Public
9.="- .-=="i,     .._ License as published by the Free Software 9.="- .-=="i,     .._ License as published by the Free Software
10 - .   .-<_>     .<> Foundation; either version 2 of the License, 10 - .   .-<_>     .<> Foundation; either version 2 of the License,
11     ._= =}       : or (at your option) any later version. 11     ._= =}       : or (at your option) any later version.
12    .%`+i>       _;_. 12    .%`+i>       _;_.
13    .i_,=:_.      -<s. This file is distributed in the hope that 13    .i_,=:_.      -<s. This file is distributed in the hope that
14     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 14     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
15    : ..    .:,     . . . without even the implied warranty of 15    : ..    .:,     . . . without even the implied warranty of
16    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 16    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
17  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU General 17  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU General
18..}^=.=       =       ; Public License for more details. 18..}^=.=       =       ; Public License for more details.
19++=   -.     .`     .: 19++=   -.     .`     .:
20 :     =  ...= . :.=- You should have received a copy of the GNU 20 :     =  ...= . :.=- You should have received a copy of the GNU
21 -.   .:....=;==+<; General Public License along with this file; 21 -.   .:....=;==+<; General Public License along with this file;
22  -_. . .   )=.  = see the file COPYING. If not, write to the 22  -_. . .   )=.  = see the file COPYING. If not, write to the
23    --        :-=` Free Software Foundation, Inc., 23    --        :-=` Free Software Foundation, Inc.,
24 59 Temple Place - Suite 330, 24 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA. 25 Boston, MA 02111-1307, USA.
26 26
27*/ 27*/
28 28
29#include "backuprestore.h" 29#include "backuprestore.h"
30#include "errordialog.h" 30#include "errordialog.h"
31 31
32/* OPIE */ 32/* OPIE */
33#include <qpe/qpeapplication.h> 33#include <qpe/qpeapplication.h>
34#include <qpe/resource.h> 34#include <qpe/resource.h>
35#include <qpe/config.h> 35#include <qpe/config.h>
36#include <opie2/odebug.h> 36#include <opie2/odebug.h>
37#include <opie2/odevice.h>
37#include <opie2/ostorageinfo.h> 38#include <opie2/ostorageinfo.h>
38#include <opie2/ofiledialog.h> 39#include <opie2/ofiledialog.h>
39#include <opie2/owait.h> 40#include <opie2/owait.h>
40using namespace Opie::Core; 41using namespace Opie::Core;
41using namespace Opie::Ui; 42using namespace Opie::Ui;
42 43
43/* QT */ 44/* QT */
44#include <qapplication.h> 45#include <qapplication.h>
45#include <qmultilineedit.h> 46#include <qmultilineedit.h>
46#include <qdir.h> 47#include <qdir.h>
47#include <qfile.h> 48#include <qfile.h>
48#include <qfileinfo.h> 49#include <qfileinfo.h>
49#include <qlistview.h> 50#include <qlistview.h>
50#include <qpushbutton.h> 51#include <qpushbutton.h>
51#include <qradiobutton.h> 52#include <qradiobutton.h>
52#include <qheader.h> 53#include <qheader.h>
53#include <qmessagebox.h> 54#include <qmessagebox.h>
54#include <qcombobox.h> 55#include <qcombobox.h>
55#include <qlist.h> 56#include <qlist.h>
56#include <qregexp.h> 57#include <qregexp.h>
57#include <qtextstream.h> 58#include <qtextstream.h>
58#include <qtextview.h> 59#include <qtextview.h>
59#include <qlineedit.h> 60#include <qlineedit.h>
60#include <qstringlist.h> 61#include <qstringlist.h>
61 62
62/* STD */ 63/* STD */
63#include <errno.h> 64#include <errno.h>
64#include <stdlib.h> 65#include <stdlib.h>
65#include <unistd.h> 66#include <unistd.h>
66#include <sys/stat.h> 67#include <sys/stat.h>
67#include <dirent.h> 68#include <dirent.h>
68 69
69#define HEADER_NAME 0 70#define HEADER_NAME 0
70#define HEADER_BACKUP 1 71#define HEADER_BACKUP 1
71#define BACKUP_LOCATION 2 72#define BACKUP_LOCATION 2
72 73
73#define EXTENSION ".bck" 74#define EXTENSION ".bck"
74 75
75const QString tempFileName = "/tmp/backup.err"; 76const QString tempFileName = "/tmp/backup.err";
76 77
77BackupAndRestore::BackupAndRestore( QWidget* parent, const char* name, WFlags fl) 78BackupAndRestore::BackupAndRestore( QWidget* parent, const char* name, WFlags fl)
78 : BackupAndRestoreBase(parent, name, fl) 79 : BackupAndRestoreBase(parent, name, fl)
79{ 80{
80 backupList->header()->hide(); 81 backupList->header()->hide();
81 restoreList->header()->hide(); 82 restoreList->header()->hide();
82 locationList->header()->hide(); 83 locationList->header()->hide();
83 connect( backupButton, SIGNAL( clicked() ), this, SLOT( backup() ) ); 84 connect( backupButton, SIGNAL( clicked() ), this, SLOT( backup() ) );
84 connect( restoreButton, SIGNAL( clicked() ), this, SLOT( restore() ) ); 85 connect( restoreButton, SIGNAL( clicked() ), this, SLOT( restore() ) );
@@ -234,97 +235,181 @@ void BackupAndRestore::selectItem(QListViewItem *currentItem)
234 if(currentItem->text(HEADER_BACKUP) == "B") 235 if(currentItem->text(HEADER_BACKUP) == "B")
235 { 236 {
236 currentItem->setPixmap(HEADER_NAME, Resource::loadPixmap("backup/null")); 237 currentItem->setPixmap(HEADER_NAME, Resource::loadPixmap("backup/null"));
237 currentItem->setText(HEADER_BACKUP, ""); 238 currentItem->setText(HEADER_BACKUP, "");
238 } 239 }
239 else 240 else
240 { 241 {
241 currentItem->setPixmap(HEADER_NAME, Resource::loadPixmap("backup/check")); 242 currentItem->setPixmap(HEADER_NAME, Resource::loadPixmap("backup/check"));
242 currentItem->setText(HEADER_BACKUP, "B"); 243 currentItem->setText(HEADER_BACKUP, "B");
243 } 244 }
244} 245}
245 246
246void BackupAndRestore::scanForApplicationSettings() 247void BackupAndRestore::scanForApplicationSettings()
247{ 248{
248 QDir d( QDir::homeDirPath() + "/" + QString( applicationSettings->text(BACKUP_LOCATION) ) ); 249 QDir d( QDir::homeDirPath() + "/" + QString( applicationSettings->text(BACKUP_LOCATION) ) );
249 d.setFilter( QDir::Dirs | QDir::Files | QDir::NoSymLinks ); 250 d.setFilter( QDir::Dirs | QDir::Files | QDir::NoSymLinks );
250 const QFileInfoList *list = d.entryInfoList(); 251 const QFileInfoList *list = d.entryInfoList();
251 QFileInfoListIterator it( *list ); 252 QFileInfoListIterator it( *list );
252 QFileInfo *fi; 253 QFileInfo *fi;
253 while ( (fi=it.current()) ) 254 while ( (fi=it.current()) )
254 { 255 {
255 //odebug << (d.path()+"/"+fi->fileName()).latin1() << oendl; 256 //odebug << (d.path()+"/"+fi->fileName()).latin1() << oendl;
256 if ( ( fi->fileName() != "." ) && ( fi->fileName() != ".." ) ) 257 if ( ( fi->fileName() != "." ) && ( fi->fileName() != ".." ) )
257 { 258 {
258 QListViewItem *newItem = new QListViewItem(applicationSettings, fi->fileName()); 259 QListViewItem *newItem = new QListViewItem(applicationSettings, fi->fileName());
259 selectItem(newItem); 260 selectItem(newItem);
260 } 261 }
261 ++it; 262 ++it;
262 } 263 }
263} 264}
264 265
265/** 266/**
266 * The "Backup" button has been pressed. Get a list of all of the files that 267 * The "Backup" button has been pressed. Get a list of all of the files that
267 * should be backed up. If there are no files, emit and error and exit. 268 * should be backed up. If there are no files, emit and error and exit.
268 * Determine the file name to store the backup in. Backup the file(s) using 269 * Determine the file name to store the backup in. Backup the file(s) using
269 * tar and gzip --best. Report failure or success 270 * tar and gzip --best. Report failure or success
270 */ 271 */
271void BackupAndRestore::backup() 272void BackupAndRestore::backup()
272{ 273{
273 if ( cb_type_userdata->isChecked() ) 274 if ( cb_type_userdata->isChecked() )
274 backupUserData(); 275 backupUserData();
275 else 276 else
276 backupRootFs(); 277 backupRootFs();
277} 278}
278 279
279 280
280void BackupAndRestore::backupRootFs() 281void BackupAndRestore::backupRootFs()
281{ 282{
282 QMessageBox::critical(this, "Message", "Not Yet Implemented", "Ok" ); 283//#define MDEBUG
284#ifndef MDEBUG
285 QMessageBox::critical( this, "Opie-Backup", "<qt>This feature is not yet implemented.</qt>", "Bummer!" );
286 return;
287#endif
288 // call 'mount' and parse its output to gather the device on which the root partition is mounted
289 FILE* mountp = popen( "mount", "r" );
290 QString device;
291 QString mountpoint;
292 {
293 QTextStream mounto( mountp, IO_ReadOnly );
294 QString on;
295 QString type;
296 QString filesystem;
297 QString options;
298 while ( !mounto.atEnd() )
299 {
300 mounto >> device >> on >> mountpoint >> type >> filesystem >> options;
301 if ( mountpoint == "/" ) break;
302 }
303 odebug << device << " is formatted w/ " << filesystem << " and mounted on " << mountpoint << oendl;
304
305 if ( !mountpoint.startsWith( "/dev/mtdblock" ) )
306 {
307 QMessageBox::critical( this, "Can't backup!", QString( "<qt>unsupported rootfs %1 - needs to be /dev/mtdblockN</qt>").arg( device ), "Ok" );
308#ifndef MDEBUG
309 return;
310#endif
311 }
312 } // at this point, the QTextStream has been destroy and we can close the FILE*
313 pclose( mountp );
314
315#ifndef MDEBUG
316 int rootmtd = device.right( 1 ).toInt();
317#else
318 int rootmtd = 0;
319#endif
320 odebug << "root mtdblock seems to be '" << rootmtd << "'" << oendl;
321
322 // scan /proc/mtd to gather the size and erasesize of the root mtdblock
323 QFile procmtdf( "/proc/mtd" );
324 if ( !procmtdf.open( IO_ReadOnly ) )
325 {
326 QMessageBox::critical( this, "Can't backup!", "<qt>Can't open /proc/mtd</qt>", "Ok" );
327 }
328
329 QTextStream procmtd( &procmtdf );
330 for ( int i = 0; i <= rootmtd; ++i ) procmtd.readLine(); // skip uninteresting things
331 QString dev;
332 QString size;
333 QString erasesize;
334 QString devname;
335 procmtd >> dev >> size >> erasesize >> devname;
336
337 odebug << "device " << dev << " size = " << size << ", erase size = " << erasesize << ", name = " << devname << "\"" << oendl;
338
339 // compute pad
340 QString pad = "--pad";
341 switch ( ODevice::inst()->model() )
342 {
343 case Model_Zaurus_SL5000: pad = "--pad=14680064"; break;
344 case Model_Zaurus_SL5500: pad = "--pad=14680064"; break;
345 // FIXME: Add Beagle and SIMpad
346 }
347
348 // compute eraseblock
349 QString eraseblock = "--eraseblock=0x" + erasesize;
350
351 // compute output
352 QString outputFile = "--output=" + backupLocations[storeToLocation->currentText()];
353 QDateTime datetime = QDateTime::currentDateTime();
354 QString dateString = QString::number( datetime.date().year() ) + QString::number( datetime.date().month() ).rightJustify(2, '0') +
355 QString::number( datetime.date().day() ).rightJustify(2, '0');
356 outputFile += "/initrd.bin-" + dateString;
357
358 // call mkfs.jffs2 to create the backup
359 QString cmdline = QString( "mkfs.jffs2 --root=/ %1 --little-endian %2 %3 -n" ).arg( outputFile ).arg( pad ).arg( eraseblock );
360 owarn << "Calling '" << cmdline << "'" << oendl;
361
362#ifndef MDEBUG
363 ::system( cmdline );
364#endif
365
366 // FIXME: Add image postprocessing for C7x0 and C8x0, for Beagle, for SIMpad
367
283} 368}
284 369
285void BackupAndRestore::backupUserData() 370void BackupAndRestore::backupUserData()
286{ 371{
287 QString backupFiles; 372 QString backupFiles;
288 if(getBackupFiles(backupFiles, NULL) == 0) 373 if(getBackupFiles(backupFiles, NULL) == 0)
289 { 374 {
290 QMessageBox::critical(this, "Message", 375 QMessageBox::critical(this, "Message",
291 "No items selected.",QString("Ok") ); 376 "No items selected.",QString("Ok") );
292 return; 377 return;
293 } 378 }
294 379
295 OWait *owait = new OWait(); 380 OWait *owait = new OWait();
296 Global::statusMessage( tr( "Backing up..." ) ); 381 Global::statusMessage( tr( "Backing up..." ) );
297 owait->show(); 382 owait->show();
298 qApp->processEvents(); 383 qApp->processEvents();
299 384
300 QString outputFile = backupLocations[storeToLocation->currentText()]; 385 QString outputFile = backupLocations[storeToLocation->currentText()];
301 386
302 QDateTime datetime = QDateTime::currentDateTime(); 387 QDateTime datetime = QDateTime::currentDateTime();
303 QString dateString = QString::number( datetime.date().year() ) + QString::number( datetime.date().month() ).rightJustify(2, '0') + 388 QString dateString = QString::number( datetime.date().year() ) + QString::number( datetime.date().month() ).rightJustify(2, '0') +
304 QString::number( datetime.date().day() ).rightJustify(2, '0'); 389 QString::number( datetime.date().day() ).rightJustify(2, '0');
305 390
306 outputFile += "/" + dateString; 391 outputFile += "/" + dateString;
307 392
308 QString t = outputFile; 393 QString t = outputFile;
309 int c = 1; 394 int c = 1;
310 while(QFile::exists(outputFile + EXTENSION)) 395 while(QFile::exists(outputFile + EXTENSION))
311 { 396 {
312 outputFile = t + QString("%1").arg(c); 397 outputFile = t + QString("%1").arg(c);
313 c++; 398 c++;
314 } 399 }
315 400
316 // We execute tar and compressing its output with gzip.. 401 // We execute tar and compressing its output with gzip..
317 // The error output will be written into a temp-file which could be provided 402 // The error output will be written into a temp-file which could be provided
318 // for debugging.. 403 // for debugging..
319 odebug << "Storing file: " << outputFile.latin1() << "" << oendl; 404 odebug << "Storing file: " << outputFile.latin1() << "" << oendl;
320 outputFile += EXTENSION; 405 outputFile += EXTENSION;
321 406
322 QString commandLine = QString( "cd %1 && (tar -X %1 -cz %2 Applications/backup/exclude -f %3 ) 2> %4" ).arg( QDir::homeDirPath() ) 407 QString commandLine = QString( "cd %1 && (tar -X %1 -cz %2 Applications/backup/exclude -f %3 ) 2> %4" ).arg( QDir::homeDirPath() )
323 .arg( getExcludeFile() ) 408 .arg( getExcludeFile() )
324 .arg( backupFiles ) 409 .arg( backupFiles )
325 .arg( outputFile.latin1() ) 410 .arg( outputFile.latin1() )
326 .arg( tempFileName.latin1() ); 411 .arg( tempFileName.latin1() );
327 412
328 odebug << commandLine << oendl; 413 odebug << commandLine << oendl;
329 414
330 int r = system( commandLine ); 415 int r = system( commandLine );