@@ -162,6 +162,7 @@ func (fms *FileManagerService) ConfigApply(ctx context.Context,
162162 return model .Error , errors .New ("fileOverview is nil" )
163163 }
164164
165+ // check if any file in request is outside the allowed directories
165166 allowedErr := fms .checkAllowedDirectory (fileOverview .GetFiles ())
166167 if allowedErr != nil {
167168 return model .Error , allowedErr
@@ -355,18 +356,28 @@ func (fms *FileManagerService) DetermineFileActions(
355356 // if file is in manifestFiles but not in modified files, file has been deleted
356357 // copy contents, set file action
357358 for fileName , manifestFile := range filesMap {
358- _ , exists := modifiedFiles [fileName ]
359+ _ , existsInReq := modifiedFiles [fileName ]
359360
361+ // allowed directories may have been updated since manifest file was written
362+ // if file is outside allowed directories skip deletion and return error
360363 if ! fms .agentConfig .IsDirectoryAllowed (fileName ) {
361364 return nil , fmt .Errorf ("error deleting file %s: file not in allowed directories" , fileName )
362365 }
363366
367+ // if file is unmanaged skip deletion
368+ if manifestFile .GetUnmanaged () {
369+ slog .DebugContext (ctx , "Skipping unmanaged file deletion" , "file_name" , fileName )
370+ continue
371+ }
372+
373+ // if file doesn't exist on disk skip deletion
364374 if _ , err := os .Stat (fileName ); os .IsNotExist (err ) {
365375 slog .DebugContext (ctx , "File already deleted, skipping" , "file" , fileName )
366376 continue
367377 }
368378
369- if ! exists {
379+ // go ahead and delete the file
380+ if ! existsInReq {
370381 fileDiff [fileName ] = & model.FileCache {
371382 File : manifestFile ,
372383 Action : model .Delete ,
@@ -382,6 +393,7 @@ func (fms *FileManagerService) DetermineFileActions(
382393
383394 // if file is unmanaged, action is set to unchanged so file is skipped when performing actions
384395 if modifiedFile .File .GetUnmanaged () {
396+ slog .DebugContext (ctx , "Skipping unmanaged file updates" , "file_name" , fileName )
385397 continue
386398 }
387399 // if file doesn't exist in the current files, file has been added
@@ -729,6 +741,7 @@ func (fms *FileManagerService) convertToManifestFile(file *mpi.File, referenced
729741 Size : file .GetFileMeta ().GetSize (),
730742 Hash : file .GetFileMeta ().GetHash (),
731743 Referenced : referenced ,
744+ Unmanaged : file .GetUnmanaged (),
732745 },
733746 }
734747}
@@ -750,6 +763,7 @@ func (fms *FileManagerService) convertToFile(manifestFile *model.ManifestFile) *
750763 Hash : manifestFile .ManifestFileMeta .Hash ,
751764 Size : manifestFile .ManifestFileMeta .Size ,
752765 },
766+ Unmanaged : manifestFile .ManifestFileMeta .Unmanaged ,
753767 }
754768}
755769
0 commit comments