refactory the code and add CreateTargetTarfile in fs_util.go
This commit is contained in:
parent
616eb83d92
commit
45c43a2c89
|
|
@ -54,18 +54,15 @@ func (b *AzureBlob) UnpackTarFromBuildContext() (string, error) {
|
||||||
return parts.Host, err
|
return parts.Host, err
|
||||||
}
|
}
|
||||||
|
|
||||||
//Create directory and file for downloading context file
|
// Create directory and target file for downloading the context file
|
||||||
directory := constants.BuildContextDir
|
directory := constants.BuildContextDir
|
||||||
tarPath := filepath.Join(directory, constants.ContextTar)
|
tarPath := filepath.Join(directory, constants.ContextTar)
|
||||||
if err := os.MkdirAll(directory, 0750); err != nil {
|
file, err := util.CreateTargetTarfile(tarPath)
|
||||||
return directory, err
|
|
||||||
}
|
|
||||||
file, err := os.Create(tarPath)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return directory, err
|
return tarPath, err
|
||||||
}
|
}
|
||||||
|
|
||||||
//Downloading contextfile from Azure Blob Storage
|
// Downloading contextfile from Azure Blob Storage
|
||||||
p := azblob.NewPipeline(credential, azblob.PipelineOptions{})
|
p := azblob.NewPipeline(credential, azblob.PipelineOptions{})
|
||||||
blobURL := azblob.NewBlobURL(*u, p)
|
blobURL := azblob.NewBlobURL(*u, p)
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
|
||||||
|
|
@ -640,3 +640,17 @@ func setFilePermissions(path string, mode os.FileMode, uid, gid int) error {
|
||||||
// Must chmod after chown because chown resets the file mode.
|
// Must chmod after chown because chown resets the file mode.
|
||||||
return os.Chmod(path, mode)
|
return os.Chmod(path, mode)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CreateTargetTarfile creates target tar file for downloading the context file.
|
||||||
|
// Make directory if directory does not exist
|
||||||
|
func CreateTargetTarfile(tarpath string) (*os.File, error) {
|
||||||
|
baseDir := filepath.Dir(tarpath)
|
||||||
|
if _, err := os.Lstat(baseDir); os.IsNotExist(err) {
|
||||||
|
logrus.Debugf("baseDir %s for file %s does not exist. Creating.", baseDir, tarpath)
|
||||||
|
if err := os.MkdirAll(baseDir, 0755); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return os.Create(tarpath)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue