Skip to content

Commit e50d100

Browse files
committed
code fix for rebase
1 parent c01046f commit e50d100

File tree

3 files changed

+28
-43
lines changed

3 files changed

+28
-43
lines changed

internal/config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ func registerClientFlags(fs *flag.FlagSet) {
658658
DefMaxFileSize,
659659
"Max file size in bytes.",
660660
)
661-
661+
662662
fs.Duration(
663663
ClientFileDownloadTimeoutKey,
664664
DefClientFileDownloadTimeout,

internal/file/file_manager_service.go

Lines changed: 27 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ const (
4747
executePerm = 0o111
4848
)
4949

50-
const fileDownloadTimeout = 60 * time.Second
51-
5250
type DownloadHeader struct {
5351
ETag string
5452
LastModified string
@@ -131,16 +129,16 @@ func NewFileManagerService(fileServiceClient mpi.FileServiceClient, agentConfig
131129
manifestLock *sync.RWMutex,
132130
) *FileManagerService {
133131
return &FileManagerService{
134-
agentConfig: agentConfig,
135-
fileOperator: NewFileOperator(manifestLock),
136-
fileServiceOperator: NewFileServiceOperator(agentConfig, fileServiceClient, manifestLock),
137-
fileActions: make(map[string]*model.FileCache),
138-
currentFilesOnDisk: make(map[string]*mpi.File),
139-
previousManifestFiles: make(map[string]*model.ManifestFile),
140-
externalFileHeaders: make(map[string]DownloadHeader),
141-
rollbackManifest: true,
142-
manifestFilePath: agentConfig.LibDir + "/manifest.json",
143-
manifestLock: manifestLock,
132+
agentConfig: agentConfig,
133+
fileOperator: NewFileOperator(manifestLock),
134+
fileServiceOperator: NewFileServiceOperator(agentConfig, fileServiceClient, manifestLock),
135+
fileActions: make(map[string]*model.FileCache),
136+
currentFilesOnDisk: make(map[string]*mpi.File),
137+
previousManifestFiles: make(map[string]*model.ManifestFile),
138+
externalFileHeaders: make(map[string]DownloadHeader),
139+
rollbackManifest: true,
140+
manifestFilePath: agentConfig.LibDir + "/manifest.json",
141+
manifestLock: manifestLock,
144142
}
145143
}
146144

@@ -401,22 +399,27 @@ func (fms *FileManagerService) DetermineFileActions(
401399
for _, modifiedFile := range modifiedFiles {
402400
fileName := modifiedFile.File.GetFileMeta().GetName()
403401
currentFile, ok := filesMap[fileName]
404-
// default to unchanged action
405402
modifiedFile.Action = model.Unchanged
406403

407-
// if file is unmanaged, action is set to unchanged so file is skipped when performing actions
404+
// If file is unmanaged, action is set to unchanged so file is skipped when performing actions.
408405
if modifiedFile.File.GetUnmanaged() {
409406
slog.DebugContext(ctx, "Skipping unmanaged file updates", "file_name", fileName)
410407
continue
411408
}
412409

413-
// If either the modified file or the current file has an external data source,
414-
// treat this as an ExternalFile skip the regular Add/Update checks. This
415-
// ensures external files are downloaded/validated every single time.
410+
// If it's external, we DON'T care about disk state or hashes here.
411+
// We tag it as ExternalFile and let the downloader handle the rest.
412+
if modifiedFile.File.GetExternalDataSource() != nil || (ok && currentFile.GetExternalDataSource() != nil) {
413+
slog.DebugContext(ctx, "External file detected - flagging for fetch", "file_name", fileName)
414+
modifiedFile.Action = model.ExternalFile
415+
fileDiff[fileName] = modifiedFile
416+
417+
continue
418+
}
419+
416420
// If file currently exists on disk, is being tracked in manifest and file hash is different.
417421
// Treat it as a file update.
418-
if (ok && modifiedFile.File.GetFileMeta().GetHash() != currentFile.GetFileMeta().GetHash()) ||
419-
modifiedFile.File.GetExternalDataSource() != nil || currentFile.GetExternalDataSource() != nil {
422+
if ok && modifiedFile.File.GetFileMeta().GetHash() != currentFile.GetFileMeta().GetHash() {
420423
slog.DebugContext(ctx, "Tracked file requires updating", "file_name", fileName)
421424
modifiedFile.Action = model.Update
422425
fileDiff[fileName] = modifiedFile
@@ -641,8 +644,8 @@ func (fms *FileManagerService) downloadUpdatedFilesToTempLocation(ctx context.Co
641644
for _, fileAction := range fms.fileActions {
642645
if fileAction.Action == model.ExternalFile || fileAction.Action == model.Add ||
643646
fileAction.Action == model.Update {
644-
downloadFiles = append(downloadFiles, fileAction)
645-
}
647+
downloadFiles = append(downloadFiles, fileAction)
648+
}
646649
}
647650

648651
if len(downloadFiles) == 0 {
@@ -655,7 +658,7 @@ func (fms *FileManagerService) downloadUpdatedFilesToTempLocation(ctx context.Co
655658
for _, fileAction := range downloadFiles {
656659
errGroup.Go(func() error {
657660
tempFilePath := tempFilePath(fileAction.File.GetFileMeta().GetName())
658-
661+
659662
switch fileAction.Action {
660663
case model.ExternalFile:
661664
return fms.downloadExternalFile(errGroupCtx, fileAction, tempFilePath)
@@ -684,7 +687,7 @@ actionsLoop:
684687
for _, fileAction := range fms.fileActions {
685688
var err error
686689
fileMeta := fileAction.File.GetFileMeta()
687-
tempFilePath := tempFilePath(fileAction.File.GetFileMeta().GetName())
690+
tempFilePath := tempFilePath(fileMeta.GetName())
688691
switch fileAction.Action {
689692
case model.Delete:
690693
slog.DebugContext(ctx, "Deleting file", "file", fileMeta.GetName())
@@ -901,25 +904,11 @@ func (fms *FileManagerService) downloadExternalFile(ctx context.Context, fileAct
901904
fileName := fileAction.File.GetFileMeta().GetName()
902905
fms.externalFileHeaders[fileName] = headers
903906

904-
updateErr := fms.writeContentToTempFile(ctx, contentToWrite, filePath, permission)
905-
906-
return updateErr
907-
}
908-
909-
func (fms *FileManagerService) writeContentToTempFile(
910-
ctx context.Context,
911-
content []byte,
912-
path string,
913-
permission string,
914-
) error {
915907
writeErr := fms.fileOperator.Write(
916908
ctx,
917909
contentToWrite,
918910
filePath,
919911
permission,
920-
content,
921-
path,
922-
permission,
923912
)
924913

925914
if writeErr != nil {
@@ -1001,7 +990,7 @@ func isDomainAllowed(downloadURL string, allowedDomains []string) bool {
1001990
if hostname == "" {
1002991
return false
1003992
}
1004-
993+
1005994
for _, domain := range allowedDomains {
1006995
if domain == "" {
1007996
continue

internal/model/config.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,6 @@ type ManifestFileMeta struct {
5252
Referenced bool `json:"referenced"`
5353
// File is not managed by the agent
5454
Unmanaged bool `json:"unmanaged"`
55-
// ETag of the 3rd Party external file
56-
ETag string `json:"etag"`
57-
// Last modified time of the 3rd Party external file
58-
LastModified string `json:"last_modified"`
5955
}
6056
type ConfigApplyMessage struct {
6157
Error error

0 commit comments

Comments
 (0)