[preservefiles] Save GS, munge destination

- using `from: config` now writes a JSON file
 - using @@ROOT@@ and @@USER@@ in dest does a sensible
   substitution.
This commit is contained in:
Adriaan de Groot 2018-05-23 09:09:03 -04:00
parent ac287a0ac5
commit b7890d865f
2 changed files with 31 additions and 6 deletions

View File

@ -54,6 +54,20 @@ QString targetPrefix()
return QLatin1Literal( "/" );
}
QString atReplacements( QString s )
{
Calamares::GlobalStorage* gs = Calamares::JobQueue::instance()->globalStorage();
QString root( "/" );
QString user;
if ( gs && gs->contains( "rootMountPoint" ) )
root = gs->value( "rootMountPoint" ).toString();
if ( gs && gs->contains( "username" ) )
user = gs->value( "username" ).toString();
return s.replace( "@@ROOT@@", root ).replace( "@@USER@@", user );
}
PreserveFiles::PreserveFiles( QObject* parent )
: Calamares::CppJob( parent )
{
@ -82,13 +96,19 @@ Calamares::JobResult PreserveFiles::exec()
for ( const auto it : m_items )
{
QString source = it.source;
QString dest = prefix + atReplacements( it.dest );
if ( it.type == ItemType::Log )
source = Logger::logFile();
if ( it.type == ItemType::Config )
cDebug() << "Config-preserving is not implemented yet.";
if ( source.isEmpty() )
cWarning() << "Skipping unnamed source file for" << it.dest;
{
if ( Calamares::JobQueue::instance()->globalStorage()->save( dest ) )
cWarning() << "Could not write config for" << dest;
else
++count;
}
else if ( source.isEmpty() )
cWarning() << "Skipping unnamed source file for" << dest;
else
{
QFile sourcef( source );
@ -98,7 +118,7 @@ Calamares::JobResult PreserveFiles::exec()
continue;
}
QFile destf( prefix + it.dest );
QFile destf( dest );
if ( !destf.open( QFile::WriteOnly ) )
{
sourcef.close();

View File

@ -15,7 +15,12 @@
# - *src*, to refer to a path interpreted in the host system. Relative
# paths are not recommended, and are interpreted relative to where
# Calamares is being run.
# Only one of the two other keys may be set.
# Only one of the two other keys (either *from* or *src*) may be set.
#
# The target filename is modified as follows:
# - `@@ROOT@@` is replaced by the path to the target root (may be /)
# - `@@USER@@` is replaced by the username entered by on the user
# page (may be empty, for instance if no user page is enabled)
#
# Special values for the key *from* are:
# - *log*, for the complete log file (up to the moment the preservefiles