@@ -28,12 +28,14 @@ type AssembleOptions struct {
2828}
2929
3030type AssembleCommand struct {
31- cfg * config.Values
32- containermanager containermanager.ContainerManager
33- createCmd * CreateCommand
34- rmCmd * RmCommand
35- enterCmd * EnterCommand
36- progress * ui.Progress
31+ cfg * config.Values
32+ createCmd * CreateCommand
33+ rmCmd * RmCommand
34+ enterCmd * EnterCommand
35+ createCmdRoot * CreateCommand
36+ rmCmdRoot * RmCommand
37+ enterCmdRoot * EnterCommand
38+ progress * ui.Progress
3739}
3840
3941func NewAssembleCommand (
@@ -43,13 +45,16 @@ func NewAssembleCommand(
4345 progress * ui.Progress ,
4446 printer * ui.Printer ,
4547) * AssembleCommand {
48+ cmRoot := cm .CloneAsRoot ()
4649 return & AssembleCommand {
47- cfg : cfg ,
48- containermanager : cm ,
49- createCmd : NewCreateCommand (cfg , cm , ui .NewDevNullProgress (), prompter ),
50- rmCmd : NewRmCommand (cfg , cm , prompter ),
51- enterCmd : NewEnterCommand (cfg , cm , progress , printer ),
52- progress : progress ,
50+ cfg : cfg ,
51+ createCmd : NewCreateCommand (cfg , cm , ui .NewDevNullProgress (), prompter ),
52+ rmCmd : NewRmCommand (cfg , cm , prompter ),
53+ enterCmd : NewEnterCommand (cfg , cm , progress , printer ),
54+ createCmdRoot : NewCreateCommand (cfg , cmRoot , ui .NewDevNullProgress (), prompter ),
55+ rmCmdRoot : NewRmCommand (cfg , cmRoot , prompter ),
56+ enterCmdRoot : NewEnterCommand (cfg , cmRoot , progress , printer ),
57+ progress : progress ,
5358 }
5459}
5560
@@ -97,7 +102,12 @@ func (ac *AssembleCommand) deleteItem(ctx context.Context, item manifest.Item, d
97102 ContainerNames : []string {item .Name },
98103 }
99104
100- _ , err := ac .rmCmd .Execute (ctx , opts )
105+ rmCmd := ac .rmCmd
106+ if item .Root {
107+ rmCmd = ac .rmCmdRoot
108+ }
109+
110+ _ , err := rmCmd .Execute (ctx , opts )
101111 if err != nil {
102112 ac .progress .Fail ()
103113 return fmt .Errorf ("failed to execute delete item '%s': %w" , item .Name , err )
@@ -142,7 +152,11 @@ func (ac *AssembleCommand) createItem(ctx context.Context, item manifest.Item, d
142152 ContainerAlwaysPull : item .AlwaysPull ,
143153 }
144154
145- _ , err := ac .createCmd .Execute (ctx , opts )
155+ createCmd := ac .createCmd
156+ if item .Root {
157+ createCmd = ac .createCmdRoot
158+ }
159+ _ , err := createCmd .Execute (ctx , opts )
146160 if err != nil {
147161 ac .progress .Fail ()
148162 return err
@@ -183,8 +197,12 @@ func (ac *AssembleCommand) joinHooks(hooks []string) string {
183197}
184198
185199func (ac * AssembleCommand ) setupBox (ctx context.Context , item manifest.Item ) error {
200+ enterCmd := ac .enterCmd
201+ if item .Root {
202+ enterCmd = ac .enterCmdRoot
203+ }
186204 if item .StartNow {
187- _ , err := ac . enterCmd .Execute (ctx , EnterOptions {
205+ _ , err := enterCmd .Execute (ctx , EnterOptions {
188206 ContainerName : item .Name ,
189207 NoTTY : true ,
190208 CustomCommand : []string {"true" }, // we just want to run the init hooks, so we can skip the shell
@@ -203,7 +221,7 @@ func (ac *AssembleCommand) setupBox(ctx context.Context, item manifest.Item) err
203221 }
204222 }
205223 for _ , app := range item .ExportedApps {
206- _ , err := ac . enterCmd .Execute (ctx , EnterOptions {
224+ _ , err := enterCmd .Execute (ctx , EnterOptions {
207225 ContainerName : item .Name ,
208226 NoTTY : true ,
209227 CustomCommand : []string {"distrobox-export" , "--app" , app },
@@ -226,7 +244,7 @@ func (ac *AssembleCommand) setupBox(ctx context.Context, item manifest.Item) err
226244 }
227245 }
228246 for _ , bin := range item .ExportedBins {
229- _ , err := ac . enterCmd .Execute (ctx , EnterOptions {
247+ _ , err := enterCmd .Execute (ctx , EnterOptions {
230248 ContainerName : item .Name ,
231249 NoTTY : true ,
232250 CustomCommand : []string {"distrobox-export" , "--bin" , bin , "--export-path" , item .ExportedBinsPath },
0 commit comments