Skip to content

Commit

Permalink
Use client's temp util when creating temp dirs
Browse files Browse the repository at this point in the history
  • Loading branch information
barbelity authored Apr 17, 2019
1 parent 138ff67 commit 6773abc
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 26 deletions.
12 changes: 4 additions & 8 deletions executers/dependenciesutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,20 +141,16 @@ func performHeadRequest(auth auth.ArtifactoryDetails, client *httpclient.HttpCli
}

// Creating dependency with the mod file in the temp directory
func createDependencyInTemp(zipPath string) (tempDir string, err error) {
tempDir, err = fileutils.GetTempDirPath()
if err != nil {
return "", err
}
func createDependencyInTemp(zipPath, tempDir string) (err error) {
multiReader, err := multifilereader.NewMultiFileReaderAt([]string{zipPath})
if err != nil {
return "", errorutils.CheckError(err)
return errorutils.CheckError(err)
}
err = fileutils.Unzip(multiReader, multiReader.Size(), tempDir)
if err != nil {
return "", errorutils.CheckError(err)
return errorutils.CheckError(err)
}
return tempDir, nil
return nil
}

// Returns the actual path to the dependency.
Expand Down
24 changes: 12 additions & 12 deletions executers/dependenciesutils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ func TestEncodeDecodePath(t *testing.T) {
}

func TestCreateDependency(t *testing.T) {
err := fileutils.CreateTempDirPath()
tempDirPath, err := fileutils.CreateTempDir()
if err != nil {
t.Error(err)
}
defer fileutils.RemoveTempDir()
defer fileutils.RemoveTempDir(tempDirPath)
baseDir, err := getBaseDir()
if err != nil {
t.Error(err)
Expand All @@ -83,11 +83,11 @@ func TestCreateDependency(t *testing.T) {
modContent: []byte(modContent),
zipPath: filepath.Join(cachePath, "v1.2.3.zip"),
}
tempDir, err := createDependencyInTemp(dep.GetZipPath())
err = createDependencyInTemp(dep.GetZipPath(), tempDirPath)
if err != nil {
t.Error(err)
}
path := filepath.Join(tempDir, "github.com", "[email protected]", "test.go")
path := filepath.Join(tempDirPath, "github.com", "[email protected]", "test.go")

exists, err := fileutils.IsFileExists(path, false)
if err != nil {
Expand All @@ -97,18 +97,18 @@ func TestCreateDependency(t *testing.T) {
if !exists {
t.Error(fmt.Sprintf("Missing %s", path))
}
err = os.RemoveAll(filepath.Join(tempDir, "github.com"))
err = os.RemoveAll(filepath.Join(tempDirPath, "github.com"))
if err != nil {
t.Error(err)
}
}

func TestGetModPath(t *testing.T) {
err := fileutils.CreateTempDirPath()
tempDirPath, err := fileutils.CreateTempDir()
if err != nil {
t.Error(err)
}
defer fileutils.RemoveTempDir()
defer fileutils.RemoveTempDir(tempDirPath)
baseDir, err := getBaseDir()
if err != nil {
t.Error(err)
Expand All @@ -120,18 +120,18 @@ func TestGetModPath(t *testing.T) {
modContent: []byte(modContent),
zipPath: filepath.Join(cachePath, "v1.2.3.zip"),
}
pwd := PackageWithDeps{Dependency: &dep}
tempDir, err := createDependencyInTemp(dep.GetZipPath())
pwd := PackageWithDeps{Dependency: &dep, depsTempDir: tempDirPath}
err = createDependencyInTemp(dep.GetZipPath(), tempDirPath)
if err != nil {
t.Error(err)
}
modPath := pwd.getModPathInTemp(tempDir)
path := filepath.Join(tempDir, "github.com", "[email protected]", "go.mod")
modPath := pwd.getModPathInTemp(tempDirPath)
path := filepath.Join(tempDirPath, "github.com", "[email protected]", "go.mod")
if path != modPath {
t.Error(fmt.Sprintf("Expected %s, got %s", path, modPath))
}

err = os.RemoveAll(filepath.Join(tempDir, "github.com"))
err = os.RemoveAll(filepath.Join(tempDirPath, "github.com"))
if err != nil {
t.Error(err)
}
Expand Down
14 changes: 8 additions & 6 deletions executers/populateandpublish.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,17 @@ type PackageWithDeps struct {
cachePath string
GoModEditMessage string
originalModContent []byte
depsTempDir string
}

// Populates and publish the dependencies.
func RecursivePublish(targetRepo, goModEditMessage string, serviceManager *artifactory.ArtifactoryServicesManager) error {
err := fileutils.CreateTempDirPath()
tempDirPath, err := fileutils.CreateTempDir()
if err != nil {
return err
}
defer fileutils.RemoveTempDir()
pwd := &PackageWithDeps{GoModEditMessage: goModEditMessage}
defer fileutils.RemoveTempDir(tempDirPath)
pwd := &PackageWithDeps{GoModEditMessage: goModEditMessage, depsTempDir: tempDirPath}
err = pwd.Init()
if err != nil {
return err
Expand Down Expand Up @@ -232,11 +233,11 @@ func (pwd *PackageWithDeps) getModPathAndUnzipDependency(path string) (string, e
return "", err
}
// Unzips the zip file into temp
tempDir, err := createDependencyInTemp(pwd.Dependency.GetZipPath())
err = createDependencyInTemp(pwd.Dependency.GetZipPath(), pwd.depsTempDir)
if err != nil {
return "", err
}
path = pwd.getModPathInTemp(tempDir)
path = pwd.getModPathInTemp(pwd.depsTempDir)
return path, err
}

Expand Down Expand Up @@ -362,7 +363,8 @@ func (pwd *PackageWithDeps) setTransitiveDependencies(targetRepo string, graphDe
depsWithTrans := &PackageWithDeps{Dependency: dep,
regExp: pwd.regExp,
cachePath: pwd.cachePath,
GoModEditMessage: pwd.GoModEditMessage}
GoModEditMessage: pwd.GoModEditMessage,
depsTempDir: pwd.depsTempDir}
dependencies = append(dependencies, *depsWithTrans)
dependenciesMap[name+":"+version] = downloadedFromArtifactory
}
Expand Down

0 comments on commit 6773abc

Please sign in to comment.