Skip to content

Commit

Permalink
feat: support extract the layer
Browse files Browse the repository at this point in the history
-

Log:
  • Loading branch information
kamiyadm committed Jan 15, 2024
1 parent f450e68 commit d3a1032
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
25 changes: 25 additions & 0 deletions apps/ll-builder/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,31 @@ int main(int argc, char **argv)
}
return err.code();
} },
{ "extract",
[&](QCommandLineParser &parser) -> int {
parser.clearPositionalArguments();

parser.addPositionalArgument("extract",
"extract the layer to a directory",
"extract");
parser.addPositionalArgument("layer", "layer file path", "[layer]");
parser.addPositionalArgument("destination", "destination directory", "[destination]");

parser.process(app);

const auto layerPath = parser.positionalArguments().value(1);
const auto destination = parser.positionalArguments().value(2);

if (layerPath.isEmpty() || destination.isEmpty()) {
parser.showHelp(-1);
}

auto err = builder.extractLayer(layerPath, destination);
if (err) {
printer.printErr(LINGLONG_ERR(err.code(), err.message()).value());
}
return err.code();
} },
{ "config",
[&](QCommandLineParser &parser) -> int {
parser.clearPositionalArguments();
Expand Down
3 changes: 3 additions & 0 deletions src/linglong/builder/builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ class Builder

virtual linglong::util::Error exportLayer(const QString &destination) = 0;

virtual linglong::util::Error extractLayer(const QString &layerPath,
const QString &destination) = 0;

virtual linglong::util::Error exportBundle(const QString &outputFilepath, bool useLocalDir) = 0;

virtual util::Error push(const QString &repoUrl,
Expand Down
23 changes: 23 additions & 0 deletions src/linglong/builder/linglong_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,29 @@ linglong::util::Error LinglongBuilder::exportLayer(const QString &destination)
return Success();
}

linglong::util::Error LinglongBuilder::extractLayer(const QString &layerPath,
const QString &destination)
{
qDebug() << layerPath << destination;
const auto layerFile = package::LayerFile::openLayer(layerPath);
if (!layerFile.has_value()) {
return WrapError(NewError(layerFile.error().code(), layerFile.error().message()),
"failed to open layer file");
}

util::ensureDir(destination);

package::LayerPackager pkg;
const auto layerDir = pkg.unpack(*(*layerFile), destination);
if (!layerDir.has_value()) {
return WrapError(NewError(layerDir.error().code(), layerDir.error().message()),
"failed to unpack layer file");
}

(*layerDir)->setCleanStatus(false);
return Success();
}

linglong::util::Error LinglongBuilder::exportBundle(const QString &outputFilePath,
bool /*useLocalDir*/)
{
Expand Down
3 changes: 3 additions & 0 deletions src/linglong/builder/linglong_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ class LinglongBuilder : public QObject, public Builder

linglong::util::Error exportLayer(const QString &destination) override;

linglong::util::Error extractLayer(const QString &layerPath,
const QString &destination) override;

linglong::util::Error exportBundle(const QString &outputFilepath, bool useLocalDir) override;

linglong::util::Error push(const QString &repoUrl,
Expand Down

0 comments on commit d3a1032

Please sign in to comment.