[preservefiles] Save GS, munge destination

- using `from: config` now writes a JSON file
 - using @@ROOT@@ and @@USER@@ in dest does a sensible
   substitution.
main
Adriaan de Groot 7 years ago
parent ac287a0ac5
commit b7890d865f

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

@ -15,7 +15,12 @@
# - *src*, to refer to a path interpreted in the host system. Relative # - *src*, to refer to a path interpreted in the host system. Relative
# paths are not recommended, and are interpreted relative to where # paths are not recommended, and are interpreted relative to where
# Calamares is being run. # 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: # Special values for the key *from* are:
# - *log*, for the complete log file (up to the moment the preservefiles # - *log*, for the complete log file (up to the moment the preservefiles

Loading…
Cancel
Save