Browse files

Get the package/extract home dir working properly now. It will curren…

…tly exclude any *flashplayer* file, but I can narrow that down or add additional excludes later if necessary
  • Loading branch information...
1 parent ef2151a commit b66d0f2475f466380cac7486b6a07a42c3ec3728 @beanpole135 beanpole135 committed Oct 17, 2013
Showing with 44 additions and 16 deletions.
  1. +22 −10 lp-gui/LPGUtils.cpp
  2. +1 −1 lp-gui/LPGUtils.h
  3. +20 −5 lp-gui/LPMain.cpp
  4. +1 −0 lp-gui/LPMain.h
View
32 lp-gui/LPGUtils.cpp
@@ -192,15 +192,21 @@ QString LPGUtils::packageHomeDir(QString username, QString packageName){
//qDebug() << "Start package dir:" << username << packageName;
if(!QFile::exists("/usr/home/"+username)){ return ""; }
//Check that the package has the right extension
- if(!packageName.endsWith(".tar.gz")){ packageName.append(".tar.gz"); }
+ if(!packageName.endsWith(".home.tar.gz")){ packageName.append(".home.tar.gz"); }
//Generate any additional files to be contained in the package
//Generate the command
QString cmd = "tar -czf /usr/home/"+packageName+" -C /usr/home "+username;
+ //Create the exclude list and skip these files
+ QStringList excludes;
+ excludes << "*flashplayer*"; //Don't overwrite the flash plugin
+ for(int i=0; i<excludes.length(); i++){
+ cmd.replace("-czf /usr/home", " --exclude \'"+excludes[i]+"\' -czf /usr/home");
+ }
//Run the command
- //qDebug() << "Run command:" << cmd;
- LPBackend::runCmd(cmd);
+ qDebug() << "Package command:" << cmd;
+ system(cmd.toUtf8()); //need to be careful with the exclude syntax (quotes) so use system command
//qDebug() << "Command return:" << QString::number(ret);
//Check that the package was created
QString packagePath;
@@ -209,21 +215,27 @@ QString LPGUtils::packageHomeDir(QString username, QString packageName){
return packagePath;
}
-QString LPGUtils::checkPackageUserPath(QString packagePath){
+bool LPGUtils::checkPackageUserPath(QString packagePath, QString *user){
+ user->clear();
//Determine if the file exists
- if( !QFile::exists(packagePath) ){ return ""; }
+ if( !QFile::exists(packagePath) ){ return false; }
//Check the username of the home dir in the package
QStringList ret = LPBackend::getCmdOutput("tar -tvf "+packagePath);
- if(ret.isEmpty()){ return ""; }
- QString username = ret[0].section(" ",2,2,QString::SectionSkipEmpty);
- return username;
+ if(ret.isEmpty()){ return false; }
+ QString username = ret[0].section(" ",2,2,QString::SectionSkipEmpty).simplified();
+ QString dirname = ret[0].section(" ",8,8,QString::SectionSkipEmpty).section("/",0,0).simplified();
+ user->append(username); //additional output
+ //Now check for the user on the local system
+ //This is just a simple check that the user directory exists, and the user/directory are the same within the package
+ return (username == dirname && QFile::exists("/usr/home/"+dirname) );
}
bool LPGUtils::extractHomeDirPackage(QString packagePath){
//Determine if the file exists
if( !QFile::exists(packagePath) ){ return false; }
- //Now extract the archive in the home directory (no overwriting of existing files)
- QString cmd = "tar -xkf "+packagePath+" -C /usr/home";
+ //Now extract the archive in the home directory
+ QString cmd = "tar -xpf "+packagePath+" -C /usr/home";
+ qDebug() << "Extract command:" << cmd;
int ret = LPBackend::runCmd(cmd);
return (ret == 0);
}
View
2 lp-gui/LPGUtils.h
@@ -19,7 +19,7 @@ class LPGUtils{
static QStringList revertDir(QString oldPath, QString newPath); //copy a dir out of a snapshot
//Functions for packaging up a user's home directory and extracting it later
static QString packageHomeDir(QString username, QString packageName);
- static QString checkPackageUserPath(QString packagePath);
+ static bool checkPackageUserPath(QString packagePath, QString *user);
static bool extractHomeDirPackage(QString packagePath);
//Function to scan the system for available harddisks/devices
static QStringList listAvailableHardDisks();
View
25 lp-gui/LPMain.cpp
@@ -16,10 +16,7 @@ LPMain::LPMain(QWidget *parent) : QMainWindow(parent), ui(new Ui::LPMain){
//Create the filesystem model and tie it to the treewidget
fsModel = new QFileSystemModel(this);
fsModel->setReadOnly(true);
- //fsModel->setFilter(QDir::AllDirs | QDir::Files | QDir::NoDotAndDotDot );
ui->treeView->setModel(fsModel);
- //Create the menu's for the special menu actions
-
//Connect the UI to all the functions
connect(ui->tool_refresh, SIGNAL(clicked()), this, SLOT(updatePoolList()) );
@@ -422,7 +419,7 @@ void LPMain::menuCompressHomeDir(QAction* act){
QString user = act->text();
qDebug() << "Compress Home Dir:" << user;
//Prompt for the package name
- QString pkgName = user+"-homedir-"+QDateTime::currentDateTime().toString("yyyyMMdd-hhmm");
+ QString pkgName = user+"-"+QDateTime::currentDateTime().toString("yyyyMMdd-hhmm");
bool ok;
pkgName = QInputDialog::getText(this, tr("Package Name"), tr("Name of the package to create:"), QLineEdit::Normal, pkgName, &ok);
if(!ok || pkgName.isEmpty() ){ return; } //cancelled
@@ -440,7 +437,25 @@ void LPMain::menuCompressHomeDir(QAction* act){
void LPMain::menuExtractHomeDir(){
qDebug() << "Extract Home Dir";
-
+ //Get the file path from the user
+ QString filePath = QFileDialog::getOpenFileName(this,tr("Find Home Dir Package"), "/usr/home", tr("Home Dir Package (*.home.tar.gz)") );
+ if(filePath.isEmpty() || !QFile::exists(filePath)){ return; } //cancelled
+ //Now check if the user in the package is also on the system
+ QString username;
+ bool ok = LPGUtils::checkPackageUserPath(filePath, &username);
+ if(!ok){
+ QMessageBox::warning(this,tr("User Missing"),QString(tr("The user (%1) does not exist on this system. Please create this user first and then try again.")).arg(username) );
+ //return;
+ }
+ //Now extract the package
+ ok = LPGUtils::extractHomeDirPackage(filePath);
+ //Now report the results
+ if(ok){
+ QMessageBox::information(this,tr("Package Extracted"), QString(tr("The package was successfully extracted within %1")).arg("/usr/home/"+username) );
+ }else{
+ QMessageBox::warning(this, tr("Package Failure"), QString(tr("The package could not be extracted within %1")).arg("/usr/home/"+username) );
+ }
+
}
// ==== Disks Menu ====
View
1 lp-gui/LPMain.h
@@ -13,6 +13,7 @@
#include <QInputDialog>
#include <QDateTime>
#include <QTimer>
+#include <QFileDialog>
#include "LPBackend.h"
#include "LPContainers.h"

0 comments on commit b66d0f2

Please sign in to comment.