@@ -393,34 +393,42 @@ func (fms *FileManagerService) DetermineFileActions(
393393 continue
394394 }
395395
396+ fileStats , statErr := os .Stat (fileName )
397+
396398 // If file doesn't exist on disk.
397399 // Treat it as adding a new file.
398- if fileStats , statErr := os . Stat ( fileName ); errors .Is (statErr , os .ErrNotExist ) {
400+ if errors .Is (statErr , os .ErrNotExist ) {
399401 slog .DebugContext (ctx , "New untracked file to created" , "file_name" , fileName )
400402 modifiedFile .Action = model .Add
401403 fileDiff [fileName ] = modifiedFile
402404
403405 continue
404- // If file already exists on disk but is not being tracked in manifest and the file hash is different.
405- // Treat it as a file update.
406- } else if statErr == nil {
407- if fileStats .IsDir () {
408- return nil , fmt .Errorf (
409- "unable to create file %s since a directory with the same name already exists on the data plane" ,
410- fileName ,
411- )
412- }
406+ }
413407
414- metadataOfFileOnDisk , err := files . FileMeta ( fileName )
415- if err != nil {
416- return nil , fmt .Errorf ("unable to get file metadata for %s: %w" , fileName , err )
417- }
408+ // If there is an error other than not existing, return that error.
409+ if statErr != nil {
410+ return nil , fmt .Errorf ("unable to stat file %s: %w" , fileName , statErr )
411+ }
418412
419- if metadataOfFileOnDisk .GetHash () != modifiedFile .File .GetFileMeta ().GetHash () {
420- slog .DebugContext (ctx , "Untracked file requires updating" , "file_name" , fileName )
421- modifiedFile .Action = model .Update
422- fileDiff [fileName ] = modifiedFile
423- }
413+ // If there is a directory with the same name, return an error.
414+ if fileStats .IsDir () {
415+ return nil , fmt .Errorf (
416+ "unable to create file %s since a directory with the same name already exists" ,
417+ fileName ,
418+ )
419+ }
420+
421+ // If file already exists on disk but is not being tracked in manifest and the file hash is different.
422+ // Treat it as a file update.
423+ metadataOfFileOnDisk , err := files .FileMeta (fileName )
424+ if err != nil {
425+ return nil , fmt .Errorf ("unable to get file metadata for %s: %w" , fileName , err )
426+ }
427+
428+ if metadataOfFileOnDisk .GetHash () != modifiedFile .File .GetFileMeta ().GetHash () {
429+ slog .DebugContext (ctx , "Untracked file requires updating" , "file_name" , fileName )
430+ modifiedFile .Action = model .Update
431+ fileDiff [fileName ] = modifiedFile
424432 }
425433 }
426434
0 commit comments