| 43 | } |
| 44 | |
| 45 | func createAllFolders(name string, perm os.FileMode, options *UpstreamOptions) error { |
| 46 | absPath, err := filepath.Abs(name) |
| 47 | if err != nil { |
| 48 | return err |
| 49 | } |
| 50 | |
| 51 | slashPath := filepath.ToSlash(absPath) |
| 52 | pathParts := strings.Split(slashPath, "/") |
| 53 | for i := 1; i < len(pathParts); i++ { |
| 54 | dirToCreate := strings.Join(pathParts[:i+1], "/") |
| 55 | err := os.Mkdir(dirToCreate, perm) |
| 56 | if err != nil { |
| 57 | if os.IsExist(err) { |
| 58 | continue |
| 59 | } |
| 60 | |
| 61 | return errors.Errorf("error creating %s: %v", dirToCreate, err) |
| 62 | } |
| 63 | |
| 64 | if options.DirCreateCmd != "" { |
| 65 | cmdArgs := make([]string, 0, len(options.DirCreateArgs)) |
| 66 | for _, arg := range options.DirCreateArgs { |
| 67 | if arg == "{}" { |
| 68 | cmdArgs = append(cmdArgs, dirToCreate) |
| 69 | } else { |
| 70 | cmdArgs = append(cmdArgs, arg) |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | out, err := exec.Command(options.DirCreateCmd, cmdArgs...).CombinedOutput() |
| 75 | if err != nil { |
| 76 | return errors.Errorf("error executing command '%s %s': %s => %v", options.DirCreateCmd, strings.Join(cmdArgs, " "), string(out), err) |
| 77 | } |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | return nil |
| 82 | } |
| 83 | |
| 84 | func untarNext(tarReader *tar.Reader, options *UpstreamOptions) (bool, error) { |
| 85 | header, err := tarReader.Next() |