Skip to content

Commit

Permalink
#119: Implement a first-pass at caching (legacy versions only).
Browse files Browse the repository at this point in the history
  • Loading branch information
fubarhouse committed Oct 7, 2019
1 parent 2631826 commit 96ffd65
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 21 deletions.
61 changes: 41 additions & 20 deletions data/version/legacy.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,41 +26,62 @@ func (drushVersion *DrushVersion) LegacyInstall() {
//
// Deprecated: Drush version manager no longer supports legacy installs.
func (drushVersion *DrushVersion) LegacyInstallTable() {
// @TODO: Rewrite this
usr, _ := user.Current()
pwd, _ := os.Getwd()
log.Infoln("Fixing dependency issue with module Console_Table")
ctFileName := "Table.inc"
ctRemotePath := "https://raw.githubusercontent.com/pear/Console_Table/master/Table.php"
ctPath := usr.HomeDir + sep + ".dvm" + sep + "versions" + sep + "drush-" + drushVersion.fullVersion + sep + "includes" + sep

dest := fmt.Sprintf("%v%v.dvm%v.cache%v", usr.HomeDir, sep, sep, sep)
destFile := fmt.Sprintf("%v%v", dest, ctFileName)

versionPath := usr.HomeDir + sep + ".dvm" + sep + "versions" + sep + "drush-" + drushVersion.fullVersion + sep + "includes" + sep + "Table.php"

ctPath := usr.HomeDir + sep + ".dvm" + sep + ".cache" + sep
ctFile := ctPath + ctFileName

_, wgetErr := wget.Run(ctRemotePath)
if wgetErr != nil {
log.Infoln("wget returned error:", wgetErr)
if _, e := os.Stat(destFile); e == nil {
log.Infof("Already downloaded '%v'.", ctFileName)
} else {
_, wgetErr := wget.Run(ctRemotePath)
if wgetErr != nil {
log.Infoln("wget returned error:", wgetErr)
} else {
copy(ctFile, destFile)
}
}

if err := copy(destFile, versionPath); err == nil {
log.Infoln("Fixed dependency issue with module Console_Table")
}
tmpFile := fmt.Sprintf("%v%vTable.php", pwd, sep)
move(tmpFile, ctFile)
}

// LegacyInstallVersion will install from a zip file which was located via git tags (manual input see ListLocal()).
//
// Deprecated: Drush version manager no longer supports legacy installs.
func (drushVersion *DrushVersion) LegacyInstallVersion() {
// @TODO: Rewrite this.
usr, _ := user.Current()
log.Infoln(fmt.Sprintf("Downloading and extracting legacy Drush version %v.", drushVersion.fullVersion))
zipFileName := drushVersion.fullVersion + ".zip"
remotePath := "https://github.com/drush-ops/drush/archive/" + zipFileName
zipPath := usr.HomeDir + sep + ".dvm" + sep + "versions" + sep
zipFile := zipPath + zipFileName
zipPathFull := fmt.Sprintf("%v%v.dvm%vversions%v%v", usr.HomeDir, sep, sep, sep, zipFileName)
mkdir(zipPath, 0755)
_, wgetErr := wget.Run(remotePath)
if wgetErr != nil {
log.Warnln("wget returned error:", wgetErr)
log.Warnln(remotePath)
zipPath := usr.HomeDir + sep + ".dvm" + sep + ".cache" + sep
//zipFile := zipPath + zipFileName
zipPathFull := fmt.Sprintf("%v%v.dvm%v.cache%v%v", usr.HomeDir, sep, sep, sep, zipFileName)
if _, e := os.Stat(zipPathFull); e == nil {
log.Infoln(fmt.Sprintf("Already downloaded Drush version v%v.", drushVersion.fullVersion))
} else {
log.Infoln(fmt.Sprintf("Downloading and extracting legacy Drush version v%v.", drushVersion.fullVersion))
mkdir(zipPath, 0755)
_, wgetErr := wget.Run(remotePath)
if wgetErr != nil {
log.Warnln("wget returned error:", wgetErr)
log.Warnln(remotePath)
}
}
move(zipFileName, zipPathFull)
exec.Command("sh", "-c", "cd "+zipPath+" && unzip "+zipFileName).Run()
remove(zipFile)
dest := fmt.Sprintf("%v%v.dvm%vversions%v", usr.HomeDir, sep, sep, sep)
destFile := fmt.Sprintf("%v%v", dest, zipFileName)

copy(zipFileName, zipPathFull)
copy(zipPathFull, destFile)
exec.Command("sh", "-c", "cd "+dest+" && unzip "+zipFileName).Run()
drushVersion.Status()
}
2 changes: 1 addition & 1 deletion data/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func (drushVersion *DrushVersion) Install() {
if installError != nil {
log.Errorf("Could not install Drush %v, cleaning installation...", drushVersion.fullVersion)
log.Errorln(installError)
remove(fmt.Sprintf("versions%v/drush-%v", dvmDirectory, sep, drushVersion.fullVersion))
remove(fmt.Sprintf("%v%vversions%vdrush-%v", dvmDirectory, sep, sep, drushVersion.fullVersion))
} else {
log.Infof("Successfully installed Drush v%v", drushVersion.fullVersion)
}
Expand Down

0 comments on commit 96ffd65

Please sign in to comment.