[libcalamares] Add a createTargetBasedirs()

- Used to ensure that the directories leading up to a given path
   exist. Implementation is incomplete and broken for now.
 - While here, avoid removing an empty pathname in removeTargetFile()
   (the empty pathname indicates a broken configuration).
main
Adriaan de Groot 5 years ago
parent 4af68365c9
commit 95936549e2

@ -338,7 +338,35 @@ System::removeTargetFile( const QString& path ) const
cWarning() << "Will not remove non-absolute path" << path; cWarning() << "Will not remove non-absolute path" << path;
return; return;
} }
QFile::remove( targetPath( path ) ); QString target = targetPath( path );
if ( !target.isEmpty() )
{
QFile::remove( target );
}
// If it was empty, a warning was already printed
}
int
System::createTargetBasedirs(const QString& path) const
{
if ( !isAbsolutePath( path ) )
{
cWarning() << "Will not create basedirs for non-absolute path" << path;
return -1;
}
QString target = targetPath( path );
if ( target.isEmpty() )
{
// If it was empty, a warning was already printed
return -1;
}
QString base( "/" );
QStringList parts = target.split( '/', QString::SplitBehavior::SkipEmptyParts );
cDebug() << parts;
return -1;
} }

@ -255,6 +255,17 @@ public:
*/ */
DLLEXPORT void removeTargetFile( const QString& path ) const; DLLEXPORT void removeTargetFile( const QString& path ) const;
/** @brief Ensure that the directories above @p path exist
*
* @param path a full pathname to a desired file.
*
* All the directory components before the last path component are
* created, as needed, with 0755 permissions. Returns the number
* of components that needed to be created; 0 if they all already
* existed, and < 0 on failure.
*/
DLLEXPORT int createTargetBasedirs( const QString& path ) const;
/** /**
* @brief getTotalMemoryB returns the total main memory, in bytes. * @brief getTotalMemoryB returns the total main memory, in bytes.
* *

Loading…
Cancel
Save