@@ -143,6 +143,48 @@ Cli::Cli(Printer &printer,
143
143
{
144
144
}
145
145
146
+ utils::error::Result<package::LayerDir> Cli::getDependLayerDir (
147
+ const package::Reference &appRef, const package::Reference &dependRef) const noexcept
148
+ {
149
+ LINGLONG_TRACE (" get layer dir of depends" )
150
+
151
+ auto appLayerDir = this ->repository .getLayerDir (appRef);
152
+ if (!appLayerDir) {
153
+ return LINGLONG_ERR (appLayerDir);
154
+ }
155
+
156
+ auto dependLayerDir = this ->repository .getLayerDir (dependRef);
157
+ if (!dependLayerDir) {
158
+ return LINGLONG_ERR (dependLayerDir);
159
+ }
160
+
161
+ if (!appLayerDir->exists (QString{ " .minified-%1" }.arg (dependRef.id ))) {
162
+ return dependLayerDir;
163
+ }
164
+
165
+ auto minified = utils::serialize::LoadJSONFile<api::types::v1::MinifiedInfo>(
166
+ dependLayerDir->absoluteFilePath (" minified.json" ));
167
+ if (!minified) {
168
+ return LINGLONG_ERR (minified);
169
+ }
170
+
171
+ const auto &appRefStr = appRef.toString ().toStdString ();
172
+ QString subRef;
173
+ for (const auto &[appRef, uuid] : minified->infos ) {
174
+ if (appRef == appRefStr) {
175
+ subRef = QString{ " minified/%1" }.arg (QString::fromStdString (uuid));
176
+ break ;
177
+ }
178
+ }
179
+
180
+ if (subRef.isEmpty ()) {
181
+ return LINGLONG_ERR (" couldn't find the association between app and depend in minified.json "
182
+ " which under the layer directory." );
183
+ }
184
+
185
+ return this ->repository .getLayerDir (dependRef, false , subRef);
186
+ }
187
+
146
188
int Cli::run (std::map<std::string, docopt::value> &args)
147
189
{
148
190
LINGLONG_TRACE (" command run" );
@@ -156,30 +198,29 @@ int Cli::run(std::map<std::string, docopt::value> &args)
156
198
return -1 ;
157
199
}
158
200
159
- auto ref = this ->repository .clearReference (*fuzzyRef,
160
- {
161
- .forceRemote = false ,
162
- .fallbackToRemote = false ,
163
- });
164
- if (!ref ) {
165
- this ->printer .printErr (ref .error ());
201
+ auto curAppRef = this ->repository .clearReference (*fuzzyRef,
202
+ {
203
+ .forceRemote = false ,
204
+ .fallbackToRemote = false ,
205
+ });
206
+ if (!curAppRef ) {
207
+ this ->printer .printErr (curAppRef .error ());
166
208
return -1 ;
167
209
}
168
210
169
- auto layerDir = this ->repository .getLayerDir (*ref , false );
170
- if (!layerDir ) {
171
- this ->printer .printErr (layerDir .error ());
211
+ auto appLayerDir = this ->repository .getLayerDir (*curAppRef , false );
212
+ if (!appLayerDir ) {
213
+ this ->printer .printErr (appLayerDir .error ());
172
214
return -1 ;
173
215
}
174
216
175
- auto info = layerDir ->info ();
217
+ auto info = appLayerDir ->info ();
176
218
if (!info) {
177
219
this ->printer .printErr (info.error ());
178
220
return -1 ;
179
221
}
180
222
181
223
std::optional<package::LayerDir> runtimeLayerDir;
182
-
183
224
if (info->runtime ) {
184
225
auto runtimeFuzzyRef =
185
226
package::FuzzyReference::parse (QString::fromStdString (*info->runtime ));
@@ -198,13 +239,13 @@ int Cli::run(std::map<std::string, docopt::value> &args)
198
239
return -1 ;
199
240
}
200
241
201
- auto layerDir = this -> repository . getLayerDir ( *runtimeRef);
202
- if (!layerDir ) {
203
- this ->printer .printErr (layerDir .error ());
242
+ auto dependRet = getDependLayerDir (*curAppRef, *runtimeRef);
243
+ if (!dependRet ) {
244
+ this ->printer .printErr (dependRet .error ());
204
245
return -1 ;
205
246
}
206
247
207
- runtimeLayerDir = *layerDir ;
248
+ runtimeLayerDir = *dependRet ;
208
249
}
209
250
210
251
auto baseFuzzyRef = package::FuzzyReference::parse (QString::fromStdString (info->base ));
@@ -223,7 +264,7 @@ int Cli::run(std::map<std::string, docopt::value> &args)
223
264
return -1 ;
224
265
}
225
266
226
- auto baseLayerDir = this -> repository . getLayerDir ( *baseRef);
267
+ auto baseLayerDir = getDependLayerDir (*curAppRef, *baseRef);
227
268
if (!baseLayerDir) {
228
269
this ->printer .printErr (LINGLONG_ERRV (baseLayerDir));
229
270
return -1 ;
@@ -242,7 +283,7 @@ int Cli::run(std::map<std::string, docopt::value> &args)
242
283
auto containers = this ->ociCLI .list ().value_or (std::vector<ocppi::types::ContainerListItem>{});
243
284
for (const auto &container : containers) {
244
285
const auto &decodedID = QString (QByteArray::fromBase64 (container.id .c_str ()));
245
- if (!decodedID.startsWith (ref ->toString ())) {
286
+ if (!decodedID.startsWith (curAppRef ->toString ())) {
246
287
continue ;
247
288
}
248
289
@@ -310,17 +351,18 @@ int Cli::run(std::map<std::string, docopt::value> &args)
310
351
if (perm->innerBinds ) {
311
352
const auto &innerBinds = perm->innerBinds ;
312
353
const auto &hostSourceDir =
313
- std::filesystem::path{ layerDir ->absolutePath ().toStdString () };
354
+ std::filesystem::path{ appLayerDir ->absolutePath ().toStdString () };
314
355
std::for_each (innerBinds->cbegin (), innerBinds->cend (), bindInnerMount);
315
356
}
316
357
}
317
358
318
359
auto container = this ->containerBuilder .create ({
319
- .appID = ref->id ,
320
- .containerID = (ref->toString () + " -" + QUuid::createUuid ().toString ()).toUtf8 ().toBase64 (),
360
+ .appID = curAppRef->id ,
361
+ .containerID =
362
+ (curAppRef->toString () + " -" + QUuid::createUuid ().toString ()).toUtf8 ().toBase64 (),
321
363
.runtimeDir = runtimeLayerDir,
322
364
.baseDir = *baseLayerDir,
323
- .appDir = *layerDir ,
365
+ .appDir = *appLayerDir ,
324
366
.patches = {},
325
367
.mounts = std::move (applicationMounts),
326
368
});
@@ -589,6 +631,11 @@ int Cli::install(std::map<std::string, docopt::value> &args)
589
631
590
632
api::types::v1::PackageManager1InstallParameters params;
591
633
auto fuzzyRef = package::FuzzyReference::parse (QString::fromStdString (tier));
634
+ if (!fuzzyRef) {
635
+ this ->printer .printErr (fuzzyRef.error ());
636
+ return -1 ;
637
+ }
638
+
592
639
params.package .id = fuzzyRef->id .toStdString ();
593
640
if (fuzzyRef->channel ) {
594
641
params.package .channel = fuzzyRef->channel ->toStdString ();
0 commit comments