Fix download source/working directory detection.
Resolve the absolute path of folders and use `filepath.HasPrefix` to
detect if the source is in the working source directory.
@@ -3,7 +3,6 @@ package file
import (
"fmt"
"path/filepath"
- "strings"
"github.com/openshift/source-to-image/pkg/api"
"github.com/openshift/source-to-image/pkg/api/constants"
@@ -36,9 +35,18 @@ func (f *File) Download(config *api.Config) (*git.SourceInfo, error) {
}
glog.V(1).Infof("Copying sources from %q to %q", copySrc, config.WorkingSourceDir)
- if strings.HasPrefix(filepath.Clean(config.WorkingSourceDir), filepath.Clean(copySrc)) {
+ absWorkingSourceDir, err := filepath.Abs(config.WorkingSourceDir)
+ if err != nil {
+ return nil, err
+ }
+ absCopySrc, err := filepath.Abs(copySrc)
+ if err != nil {
+ return nil, err
+ }
+ if filepath.HasPrefix(absWorkingSourceDir, absCopySrc) {
return nil, RecursiveCopyError{error: fmt.Errorf("recursive copy requested, source directory %q contains the target directory %q", copySrc, config.WorkingSourceDir)}
}
+
if copySrc != config.WorkingSourceDir {
f.KeepSymlinks(config.KeepSymlinks)
err := f.CopyContents(copySrc, config.WorkingSourceDir)
