Fetch now wants full name (13.2-RELEASE), limit pkg to download/extract
This commit is contained in:
parent
6a8b022165
commit
26b8973c6c
138
cmd/fetch.go
138
cmd/fetch.go
@ -23,7 +23,9 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
FetchFiles = []string{"base.txz", "lib32.txz", "src.txz"}
|
// TODO : Make this a config/cmd line setting
|
||||||
|
//FetchFiles = []string{"base.txz", "lib32.txz", "src.txz"}
|
||||||
|
FetchFiles = []string{"base.txz"}
|
||||||
)
|
)
|
||||||
|
|
||||||
// TODO: Check if files already exist
|
// TODO: Check if files already exist
|
||||||
@ -66,9 +68,9 @@ func fetchRelease(release string, proto string, arch string, datastore string, f
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create download/XX.X-RELEASE dataset if necessary
|
// Create download/XX.X dataset if necessary
|
||||||
thisDownloadDsName := fmt.Sprintf("%s/%s-RELEASE", downloadDsName, release)
|
thisDownloadDsName := fmt.Sprintf("%s/%s", downloadDsName, release)
|
||||||
thisDownloadDsMountPoint := fmt.Sprintf("%s/%s-RELEASE", downloadDsMountPoint, release)
|
thisDownloadDsMountPoint := fmt.Sprintf("%s/%s", downloadDsMountPoint, release)
|
||||||
exist, err = doZfsDatasetExist(thisDownloadDsName)
|
exist, err = doZfsDatasetExist(thisDownloadDsName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Error accessing dataset %s: %v\n", thisDownloadDsName, err)
|
return fmt.Errorf("Error accessing dataset %s: %v\n", thisDownloadDsName, err)
|
||||||
@ -82,9 +84,9 @@ func fetchRelease(release string, proto string, arch string, datastore string, f
|
|||||||
|
|
||||||
var fetchUrl string
|
var fetchUrl string
|
||||||
if len(fetchFrom) > 0 {
|
if len(fetchFrom) > 0 {
|
||||||
fetchUrl = fmt.Sprintf("%s/%s-RELEASE", fetchFrom, release)
|
fetchUrl = fmt.Sprintf("%s/%s", fetchFrom, release)
|
||||||
} else {
|
} else {
|
||||||
fetchUrl = fmt.Sprintf("%s://%s/%s/%s/%s-RELEASE", proto, ReleaseServer, ReleaseRootDir, arch, release)
|
fetchUrl = fmt.Sprintf("%s://%s/%s/%s/%s", proto, ReleaseServer, ReleaseRootDir, arch, release)
|
||||||
}
|
}
|
||||||
log.Debugf("FetchURL = %s", fetchUrl)
|
log.Debugf("FetchURL = %s", fetchUrl)
|
||||||
|
|
||||||
@ -153,9 +155,9 @@ func extractRelease(release string, datastore string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create releases/XX.X-RELEASE dataset if necessary
|
// Create releases/XX.X dataset if necessary
|
||||||
thisReleaseDsName := fmt.Sprintf("%s/%s-RELEASE", releaseDsName, release)
|
thisReleaseDsName := fmt.Sprintf("%s/%s", releaseDsName, release)
|
||||||
thisReleaseDsMountPoint := fmt.Sprintf("%s/%s-RELEASE", releaseDsMountPoint, release)
|
thisReleaseDsMountPoint := fmt.Sprintf("%s/%s", releaseDsMountPoint, release)
|
||||||
exist, err = doZfsDatasetExist(thisReleaseDsName)
|
exist, err = doZfsDatasetExist(thisReleaseDsName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Error accessing dataset %s: %v\n", thisReleaseDsName, err)
|
fmt.Printf("Error accessing dataset %s: %v\n", thisReleaseDsName, err)
|
||||||
@ -169,7 +171,7 @@ func extractRelease(release string, datastore string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create releases/XX.X-RELEASE/root dataset if necessary
|
// Create releases/XX.X/root dataset if necessary
|
||||||
thisReleaseRootDsName := fmt.Sprintf("%s/root", thisReleaseDsName)
|
thisReleaseRootDsName := fmt.Sprintf("%s/root", thisReleaseDsName)
|
||||||
thisReleaseRootDsMountPoint := fmt.Sprintf("%s/root", thisReleaseDsMountPoint)
|
thisReleaseRootDsMountPoint := fmt.Sprintf("%s/root", thisReleaseDsMountPoint)
|
||||||
exist, err = doZfsDatasetExist(thisReleaseRootDsName)
|
exist, err = doZfsDatasetExist(thisReleaseRootDsName)
|
||||||
@ -185,9 +187,9 @@ func extractRelease(release string, datastore string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now extract download/$RELEASE/*.txz to releases/XX.X-RELEASE/root
|
// Now extract download/$RELEASE/*.txz to releases/XX.X/root
|
||||||
downloadDsMountPoint := fmt.Sprintf("%s/download", ds.Mountpoint)
|
downloadDsMountPoint := fmt.Sprintf("%s/download", ds.Mountpoint)
|
||||||
downloadDir := fmt.Sprintf("%s/%s-RELEASE", downloadDsMountPoint, release)
|
downloadDir := fmt.Sprintf("%s/%s", downloadDsMountPoint, release)
|
||||||
|
|
||||||
d, err := os.Open(downloadDir)
|
d, err := os.Open(downloadDir)
|
||||||
defer d.Close()
|
defer d.Close()
|
||||||
@ -201,67 +203,69 @@ func extractRelease(release string, datastore string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extract every .txz files
|
// Extract every .txz files in FetchFiles
|
||||||
for _, fi := range files {
|
for _, fi := range files {
|
||||||
if false == fi.IsDir() {
|
if false == fi.IsDir() {
|
||||||
if strings.HasSuffix(fi.Name(), ".txz") {
|
if strings.HasSuffix(fi.Name(), ".txz") {
|
||||||
ar := fmt.Sprintf("%s/%s", downloadDir, fi.Name())
|
if isStringInArray(FetchFiles, fi.Name()) {
|
||||||
fmt.Printf("Extracting file %s... ", ar)
|
ar := fmt.Sprintf("%s/%s", downloadDir, fi.Name())
|
||||||
// pure Go method, sorry this is so slow. Also I did not handle permissions in this
|
fmt.Printf("Extracting file %s to %s... ", ar, thisReleaseRootDsMountPoint)
|
||||||
/* f, err := os.Open(ar)
|
// pure Go method, sorry this is so slow. Also I did not handle permissions in this
|
||||||
defer f.Close()
|
/* f, err := os.Open(ar)
|
||||||
if err != nil {
|
defer f.Close()
|
||||||
fmt.Printf("Can not open %s: %v\n", ar, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
// xz reader
|
|
||||||
r, err := xz.NewReader(f)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("Can not read %s: %v\n", ar, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
// tar reader
|
|
||||||
tr := tar.NewReader(r)
|
|
||||||
// Iterate through the files in the archive.
|
|
||||||
for {
|
|
||||||
hdr, err := tr.Next()
|
|
||||||
if err == io.EOF {
|
|
||||||
// end of tar archive
|
|
||||||
break
|
|
||||||
}
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
fmt.Printf("Can not open %s: %v\n", ar, err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
switch hdr.Typeflag {
|
// xz reader
|
||||||
case tar.TypeDir:
|
r, err := xz.NewReader(f)
|
||||||
// create a directory
|
if err != nil {
|
||||||
dest := fmt.Sprintf("%s/%s", thisReleaseRootDsMountPoint, hdr.Name)
|
fmt.Printf("Can not read %s: %v\n", ar, err)
|
||||||
// FIXME: Access rights?
|
return
|
||||||
err = os.MkdirAll(dest, 0777)
|
}
|
||||||
if err != nil {
|
// tar reader
|
||||||
log.Fatal(err)
|
tr := tar.NewReader(r)
|
||||||
}
|
// Iterate through the files in the archive.
|
||||||
case tar.TypeReg, tar.TypeRegA:
|
for {
|
||||||
// write a file
|
hdr, err := tr.Next()
|
||||||
dest := fmt.Sprintf("%s/%s", thisReleaseRootDsMountPoint, hdr.Name)
|
if err == io.EOF {
|
||||||
w, err := os.Create(dest)
|
// end of tar archive
|
||||||
defer w.Close()
|
break
|
||||||
if err != nil {
|
}
|
||||||
log.Fatal(err)
|
if err != nil {
|
||||||
}
|
log.Fatal(err)
|
||||||
_, err = io.Copy(w, tr)
|
}
|
||||||
if err != nil {
|
switch hdr.Typeflag {
|
||||||
log.Fatal(err)
|
case tar.TypeDir:
|
||||||
}
|
// create a directory
|
||||||
|
dest := fmt.Sprintf("%s/%s", thisReleaseRootDsMountPoint, hdr.Name)
|
||||||
|
// FIXME: Access rights?
|
||||||
|
err = os.MkdirAll(dest, 0777)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
case tar.TypeReg, tar.TypeRegA:
|
||||||
|
// write a file
|
||||||
|
dest := fmt.Sprintf("%s/%s", thisReleaseRootDsMountPoint, hdr.Name)
|
||||||
|
w, err := os.Create(dest)
|
||||||
|
defer w.Close()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
_, err = io.Copy(w, tr)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
cmd := fmt.Sprintf("/usr/bin/tar xpf %s -C %s", ar, thisReleaseRootDsMountPoint)
|
||||||
|
out, err := executeCommand(cmd)
|
||||||
|
if err != nil && len(out) > 0 {
|
||||||
|
fmt.Printf("Error: %v: %s\n", err, out)
|
||||||
|
} else {
|
||||||
|
fmt.Printf("Done\n")
|
||||||
}
|
}
|
||||||
}
|
|
||||||
*/
|
|
||||||
cmd := fmt.Sprintf("/usr/bin/tar xpf %s -C %s", ar, thisReleaseRootDsMountPoint)
|
|
||||||
out, err := executeCommand(cmd)
|
|
||||||
if err != nil && len(out) > 0 {
|
|
||||||
fmt.Printf("Error: %v: %s\n", err, out)
|
|
||||||
} else {
|
|
||||||
fmt.Printf("Done\n")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user