MCPcopy Index your code
hub / github.com/devspace-sh/devspace / CalculateLocalState

Method CalculateLocalState

pkg/devspace/sync/initial.go:273–338  ·  view source on GitHub ↗
(absPath string, localState map[string]*FileInformation, ignore bool)

Source from the content-addressed store, hash-verified

271}
272
273func (i *initialSyncer) CalculateLocalState(absPath string, localState map[string]*FileInformation, ignore bool) error {
274 relativePath := getRelativeFromFullPath(absPath, i.o.LocalPath)
275
276 // We skip files that are suddenly not there anymore
277 stat, err := os.Stat(absPath)
278 if err != nil {
279 return nil
280 }
281
282 // Exclude changes on the upload exclude list
283 if i.o.UploadIgnoreMatcher != nil {
284 if i.o.UploadIgnoreMatcher.Matches(relativePath, stat.IsDir()) {
285 ignore = true
286 }
287 }
288
289 // Check for symlinks
290 isSymlink := false
291 if !ignore {
292 // Retrieve the real stat instead of the symlink one
293 lstat, err := os.Lstat(absPath)
294 if err == nil && lstat.Mode()&os.ModeSymlink != 0 {
295 // Get real path
296 targetPath, err := filepath.EvalSymlinks(absPath)
297 if err != nil {
298 return nil
299 }
300
301 stat, err = os.Stat(targetPath)
302 if err != nil {
303 return nil
304 }
305
306 isSymlink = true
307 } else if err != nil {
308 return nil
309 }
310 }
311
312 // Check if stat is somehow not there
313 if stat == nil {
314 return nil
315 } else if i.o.IgnoreMatcher != nil && !i.o.IgnoreMatcher.RequireFullScan() && i.o.IgnoreMatcher.Matches(relativePath, stat.IsDir()) {
316 return nil
317 }
318
319 if stat.IsDir() {
320 return i.calculateLocalDirState(absPath, stat, localState, isSymlink, ignore)
321 }
322
323 if !ignore {
324 // Add file to upload
325 localState[relativePath] = &FileInformation{
326 Name: relativePath,
327 Mtime: stat.ModTime().Unix(),
328 MtimeNano: stat.ModTime().UnixNano(),
329 Size: stat.Size(),
330 Mode: stat.Mode(),

Callers 2

initialSyncMethod · 0.80

Calls 8

getRelativeFromFullPathFunction · 0.70
MatchesMethod · 0.65
RequireFullScanMethod · 0.65
IsDirMethod · 0.45
ModeMethod · 0.45
ModTimeMethod · 0.45
SizeMethod · 0.45

Tested by

no test coverage detected