From 8822a1c4d6fa79d7af6481bcc013fb12df9a460f Mon Sep 17 00:00:00 2001 From: Evan Fossier Date: Thu, 12 Dec 2024 12:28:55 -0500 Subject: [PATCH] fix[datadog-installer]: Handle 'file not found' error in removeUnit function (#32066) Co-authored-by: arbll --- pkg/fleet/installer/packages/systemd.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pkg/fleet/installer/packages/systemd.go b/pkg/fleet/installer/packages/systemd.go index 679331907f7fd5..9b95672af1533d 100644 --- a/pkg/fleet/installer/packages/systemd.go +++ b/pkg/fleet/installer/packages/systemd.go @@ -108,7 +108,11 @@ func removeUnit(ctx context.Context, unit string) (err error) { span, _ := tracer.StartSpanFromContext(ctx, "remove_unit") defer func() { span.Finish(tracer.WithError(err)) }() span.SetTag("unit", unit) - return os.Remove(path.Join(systemdPath, unit)) + err = os.Remove(path.Join(systemdPath, unit)) + if err != nil && !os.IsNotExist(err) { + return err + } + return nil } func systemdReload(ctx context.Context) (err error) {