MCPcopy Create free account
hub / github.com/devspace-sh/devspace / untarNext

Method untarNext

pkg/devspace/sync/tar.go:67–165  ·  view source on GitHub ↗
(destPath string, tarReader *tar.Reader)

Source from the content-addressed store, hash-verified

65}
66
67func (u *Unarchiver) untarNext(destPath string, tarReader *tar.Reader) (bool, error) {
68 u.syncConfig.fileIndex.fileMapMutex.Lock()
69 defer u.syncConfig.fileIndex.fileMapMutex.Unlock()
70
71 header, err := tarReader.Next()
72 if err != nil {
73 if err != io.EOF {
74 return false, errors.Wrap(err, "tar next")
75 }
76
77 return false, nil
78 }
79
80 relativePath := getRelativeFromFullPath("/"+header.Name, "")
81 outFileName := path.Join(destPath, relativePath)
82 baseName := path.Dir(outFileName)
83
84 // Check if newer file is there and then don't override?
85 stat, err := os.Stat(outFileName)
86 if err == nil && !u.forceOverride {
87 if stat.ModTime().Unix() > header.FileInfo().ModTime().Unix() {
88 // Update filemap otherwise we download and download again
89 u.syncConfig.fileIndex.fileMap[relativePath] = &FileInformation{
90 Name: relativePath,
91 Mtime: stat.ModTime().Unix(),
92 Mode: stat.Mode(),
93 Size: stat.Size(),
94 IsDirectory: stat.IsDir(),
95 }
96
97 if !stat.IsDir() {
98 u.syncConfig.log.Infof("Downstream - Don't override %s because file has newer mTime timestamp", relativePath)
99 }
100 return true, nil
101 }
102 }
103
104 if err := u.createAllFolders(baseName, 0755); err != nil {
105 return false, err
106 }
107
108 if header.FileInfo().IsDir() {
109 if err := u.createAllFolders(outFileName, 0755); err != nil {
110 return false, err
111 }
112
113 u.syncConfig.fileIndex.CreateDirInFileMap(relativePath)
114 return true, nil
115 }
116
117 // Create base dir in file map if it not already exists
118 u.syncConfig.fileIndex.CreateDirInFileMap(getRelativeFromFullPath(baseName, destPath))
119
120 // Create / Override file
121 outFile, err := os.Create(outFileName)
122 if err != nil {
123 // Try again after 5 seconds
124 time.Sleep(time.Second * 5)

Callers 1

UntarMethod · 0.95

Calls 13

createAllFoldersMethod · 0.95
LockMethod · 0.80
UnlockMethod · 0.80
NextMethod · 0.80
CreateDirInFileMapMethod · 0.80
getRelativeFromFullPathFunction · 0.70
CloseMethod · 0.65
CopyMethod · 0.65
ModTimeMethod · 0.45
ModeMethod · 0.45
SizeMethod · 0.45
IsDirMethod · 0.45

Tested by

no test coverage detected