@@ -122,6 +122,45 @@ func fileContainsContainer(path, container string) bool {
122122 return strings .Contains (string (content ), "# toolbox_binary" ) && strings .Contains (string (content ), fmt .Sprintf ("name: %s" , container ))
123123}
124124
125+ // Exported function: remove all exported binaries and desktop files for a container
126+ func UnexportAll (container string ) ([]string , []string , error ) {
127+ homeDir , err := os .UserHomeDir ()
128+ if err != nil {
129+ return nil , nil , err
130+ }
131+ binDir := filepath .Join (homeDir , ".local" , "bin" )
132+ appsDir := filepath .Join (homeDir , ".local" , "share" , "applications" )
133+
134+ removedBins := []string {}
135+ removedApps := []string {}
136+
137+ binFiles , _ := os .ReadDir (binDir )
138+ for _ , f := range binFiles {
139+ if f .IsDir () {
140+ continue
141+ }
142+ path := filepath .Join (binDir , f .Name ())
143+ if fileContainsContainer (path , container ) {
144+ if err := os .Remove (path ); err == nil {
145+ removedBins = append (removedBins , path )
146+ }
147+ }
148+ }
149+
150+ appFiles , _ := os .ReadDir (appsDir )
151+ for _ , f := range appFiles {
152+ name := f .Name ()
153+ if strings .HasSuffix (name , "-" + container + ".desktop" ) {
154+ path := filepath .Join (appsDir , name )
155+ if err := os .Remove (path ); err == nil {
156+ removedApps = append (removedApps , path )
157+ }
158+ }
159+ }
160+
161+ return removedBins , removedApps , nil
162+ }
163+
125164func unexportHelp (cmd * cobra.Command , args []string ) {
126165 if utils .IsInsideContainer () {
127166 if ! utils .IsInsideToolboxContainer () {
0 commit comments