diff mbox series

[yocto-autobuilder-helper] ab-janitor: only rm trashdir files over 60s old

Message ID 20230613170501.2326478-1-tgamblin@baylibre.com
State New
Headers show
Series [yocto-autobuilder-helper] ab-janitor: only rm trashdir files over 60s old | expand

Commit Message

Trevor Gamblin June 13, 2023, 5:05 p.m. UTC
[YOCTO #14952] -- https://bugzilla.yoctoproject.org/show_bug.cgi?id=14952

Help avoid contention by adding a check to ensure files and directories
are at least 60s old when attempting to delete them from the trashdir,
in case bitbake or another process is still actively using them.

Signed-off-by: Trevor Gamblin <tgamblin@baylibre.com>
---
 janitor/ab-janitor | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

Comments

Richard Purdie June 15, 2023, 1:39 p.m. UTC | #1
On Tue, 2023-06-13 at 13:05 -0400, Trevor Gamblin wrote:
> [YOCTO #14952] -- https://bugzilla.yoctoproject.org/show_bug.cgi?id=14952
> 
> Help avoid contention by adding a check to ensure files and directories
> are at least 60s old when attempting to delete them from the trashdir,
> in case bitbake or another process is still actively using them.
> 
> Signed-off-by: Trevor Gamblin <tgamblin@baylibre.com>
> ---
>  janitor/ab-janitor | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/janitor/ab-janitor b/janitor/ab-janitor
> index 080b598..659817e 100755
> --- a/janitor/ab-janitor
> +++ b/janitor/ab-janitor
> @@ -43,7 +43,13 @@ def trash_processor(trashdir):
>          try:
>              files = os.listdir(trashdir)
>              if files:
> -                os.system("nice -n 10 ionice -c 3 rm %s/* -rf" % trashdir)
> +                for file in files:
> +                    file_path = trashdir + "/" + file
> +                    file_age = time.time() - os.path.getmtime(file_path)
> +                    if file_age >= 60:
> +                        os.system("nice -n 10 ionice -c 3 rm %s -rf" % file_path)
> +                    else:
> +                        print("Not removing '%s' - age is only %s seconds. There may be another process using it" % (file_path, str(int(file_age))))
>              else:
>                  time.sleep(120*60) # 30 minutes
>          except Exception as e:

Looks good, merged, thanks!

Cheers,

Richard
diff mbox series

Patch

diff --git a/janitor/ab-janitor b/janitor/ab-janitor
index 080b598..659817e 100755
--- a/janitor/ab-janitor
+++ b/janitor/ab-janitor
@@ -43,7 +43,13 @@  def trash_processor(trashdir):
         try:
             files = os.listdir(trashdir)
             if files:
-                os.system("nice -n 10 ionice -c 3 rm %s/* -rf" % trashdir)
+                for file in files:
+                    file_path = trashdir + "/" + file
+                    file_age = time.time() - os.path.getmtime(file_path)
+                    if file_age >= 60:
+                        os.system("nice -n 10 ionice -c 3 rm %s -rf" % file_path)
+                    else:
+                        print("Not removing '%s' - age is only %s seconds. There may be another process using it" % (file_path, str(int(file_age))))
             else:
                 time.sleep(120*60) # 30 minutes
         except Exception as e: