Browse Source

Add ability to uninstall pkg

feature/create-install-pkgs
Tovi Jaeschke-Rogers 3 years ago
parent
commit
e028d1733c
5 changed files with 116 additions and 8 deletions
  1. +41
    -0
      Archive/Unarchive.go
  2. +7
    -3
      Client/Filesystem/PickFiles.go
  3. +1
    -1
      Client/Package/CreatePackage.go
  4. +51
    -0
      Client/Package/UninstallPackage.go
  5. +16
    -4
      Client/main.go

+ 41
- 0
Archive/Unarchive.go View File

@ -149,3 +149,44 @@ func extractManifestFromArchive(tarReader *tar.Reader) (string, error) {
return manifestBytes.String(), nil return manifestBytes.String(), nil
} }
func GetPackageFilePaths(source string) ([]string, error) {
var (
inFile *os.File
gzipReader *gzip.Reader
tarReader *tar.Reader
info os.FileInfo
header *tar.Header
pkgFiles []string
e error
)
inFile, e = os.Open(source)
if e != nil {
return pkgFiles, e
}
defer inFile.Close()
gzipReader, e = gzip.NewReader(inFile)
defer gzipReader.Close()
tarReader = tar.NewReader(gzipReader)
for {
header, e = tarReader.Next()
if e == io.EOF {
break
}
if e != nil {
return pkgFiles, e
}
info = header.FileInfo()
if filepath.Base(info.Name()) == "manifest.yml" {
continue
}
pkgFiles = append(pkgFiles, header.Name)
}
return pkgFiles, nil
}

+ 7
- 3
Client/Filesystem/PickFiles.go View File

@ -3,6 +3,7 @@ package Filesystem
import ( import (
"os" "os"
"path/filepath" "path/filepath"
"strings"
"github.com/vbauerster/mpb" "github.com/vbauerster/mpb"
bolt "go.etcd.io/bbolt" bolt "go.etcd.io/bbolt"
@ -39,6 +40,7 @@ func pickFilesRecursive(rootPath string) error {
picksBucket *bolt.Bucket picksBucket *bolt.Bucket
bar *mpb.Bar bar *mpb.Bar
totalLen int totalLen int
trimF string
f string f string
e error e error
) )
@ -63,7 +65,8 @@ func pickFilesRecursive(rootPath string) error {
if len(fsStatus.NewFiles) > 0 { if len(fsStatus.NewFiles) > 0 {
for _, f = range fsStatus.NewFiles { for _, f = range fsStatus.NewFiles {
bar.Increment() bar.Increment()
e = AddFileToBucket(picksBucket, f, f)
trimF = strings.TrimPrefix(f, Variables.RootDir)
e = AddFileToBucket(picksBucket, trimF, f)
if e != nil { if e != nil {
return e return e
} }
@ -73,7 +76,8 @@ func pickFilesRecursive(rootPath string) error {
if len(fsStatus.ModifiedFiles) > 0 { if len(fsStatus.ModifiedFiles) > 0 {
for _, f = range fsStatus.ModifiedFiles { for _, f = range fsStatus.ModifiedFiles {
bar.Increment() bar.Increment()
e = AddFileToBucket(picksBucket, f, f)
trimF = strings.TrimPrefix(f, Variables.RootDir)
e = AddFileToBucket(picksBucket, trimF, f)
if e != nil { if e != nil {
return e return e
} }
@ -118,7 +122,7 @@ func PickFiles(rootPath string) error {
return pickFilesSingle(rootPath, realRootPath) return pickFilesSingle(rootPath, realRootPath)
} }
return pickFilesRecursive(rootPath)
return pickFilesRecursive(realRootPath)
} }
func ResetAllPickedFiles() error { func ResetAllPickedFiles() error {


+ 1
- 1
Client/Package/CreatePackage.go View File

@ -138,7 +138,7 @@ func CreatePackage() error {
e = editManifestFile(filepath.Join("/tmp/", "manifest.yml")) e = editManifestFile(filepath.Join("/tmp/", "manifest.yml"))
if e != nil { if e != nil {
fmt.Println(Color.Fatal(e.Error))
fmt.Println(Color.Fatal(e))
} }
// TODO: Write this file to a better spot? // TODO: Write this file to a better spot?


+ 51
- 0
Client/Package/UninstallPackage.go View File

@ -0,0 +1,51 @@
package Package
import (
"PackageManager/Archive"
"PackageManager/Color"
"errors"
"fmt"
"os"
)
func UninstallPackage(pkgs []string) error {
var (
pkgFiles []string
pkg string
f string
e error
)
for _, pkg = range pkgs {
_, e = os.Stat(pkg)
if os.IsNotExist(e) {
return errors.New(fmt.Sprintf("Invalid package %s", pkg))
}
}
for _, pkg = range pkgs {
fmt.Printf(
"Uninstalling %s...\n",
pkg,
)
pkgFiles, e = Archive.GetPackageFilePaths(pkg)
if e != nil {
return e
}
for _, f = range pkgFiles {
e = os.Remove(f)
if e != nil {
return e
}
}
fmt.Printf(
Color.Green("%s uninstalled\n"),
pkg,
)
}
return nil
}

+ 16
- 4
Client/main.go View File

@ -40,6 +40,9 @@ Filesystem diff:
-Il | -install-local -Il | -install-local
Install package from local tarball Install package from local tarball
-Rl | -remove-local
Remove package from local tarball
-ignore-deps-check -ignore-deps-check
Skip dependancies check Skip dependancies check
` `
@ -62,6 +65,8 @@ func main() {
createPackageFlagLong bool createPackageFlagLong bool
installLocalPackageFlag bool installLocalPackageFlag bool
installLocalPackageFlagLong bool installLocalPackageFlagLong bool
uninstallPackageFlag bool
uninstallPackageFlagLong bool
ignoreDepsCheckFlag bool ignoreDepsCheckFlag bool
verboseOutputFlag bool verboseOutputFlag bool
@ -110,6 +115,9 @@ func main() {
flag.BoolVar(&installLocalPackageFlag, "Il", false, "Install package from local tarball") flag.BoolVar(&installLocalPackageFlag, "Il", false, "Install package from local tarball")
flag.BoolVar(&installLocalPackageFlagLong, "install-local", false, "Install package from local tarball") flag.BoolVar(&installLocalPackageFlagLong, "install-local", false, "Install package from local tarball")
flag.BoolVar(&uninstallPackageFlag, "Rl", false, "Uninstall local package")
flag.BoolVar(&uninstallPackageFlagLong, "remove-local", false, "Uninstall local package")
flag.BoolVar(&ignoreDepsCheckFlag, "ignore-deps-check", false, "Ignore dependancies check") flag.BoolVar(&ignoreDepsCheckFlag, "ignore-deps-check", false, "Ignore dependancies check")
flag.Parse() flag.Parse()
@ -182,10 +190,14 @@ func main() {
return return
} }
if uninstallPackageFlag || uninstallPackageFlagLong {
e = Package.UninstallPackage(flag.Args())
if e != nil {
panic(e)
}
return
}
flag.Usage() flag.Usage()
fmt.Println(Color.Fatal("Nothing to do")) fmt.Println(Color.Fatal("Nothing to do"))
//e := Archive.TarGzip("/tmp/test", "/tmp/test.tar.gz")
//e := Archive.UntarGzip("/tmp/test.tar.gz", "/tmp/test")
//fmt.Println(e)
} }

Loading…
Cancel
Save