changeset 17:90eafff62b97

hrm now behaves like rm with the '-f' switch by default, so that it doesn't abort and return with a nonzero exit code if a file parameter doesn't exist. This makes it much more compatible with existing build scripts that use rm.
author Atul Varma <varmaa@toolness.com>
date Tue, 09 Dec 2008 18:39:45 -0800
parents 14f4251b156c
children 117bbabc17d3
files hrm.py
diffstat 1 files changed, 10 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/hrm.py	Tue Dec 09 13:25:09 2008 -0800
+++ b/hrm.py	Tue Dec 09 18:39:45 2008 -0800
@@ -39,6 +39,10 @@
 
 # TODO:
 #
+#   * If the '-f' parameter isn't supplied, hrm should exit with a
+#     nonzero exit code if a file doesn't exist to maintain compatibility
+#     with rm.
+#
 #   * Consider adding support for "max size" based removal, so that
 #     if a certain quota is exceeded, the minimum number of files are
 #     removed to satisfy the quota.
@@ -184,7 +188,7 @@
             filename = os.path.abspath(os.path.expanduser(arg))
             if not os.path.exists(filename):
                 print('File does not exist: %s' % arg)
-                sys.exit(-1)
+                continue
             realpath = os.path.realpath(filename)
             if (realpath.startswith(HADES_DIR) or
                 HADES_DIR.startswith(realpath)):
@@ -192,6 +196,11 @@
                 sys.exit(-1)
             files.append(filename)
 
+        if not files:
+            # For compatibility with 'rm -f', just exit w/ no
+            # error code.
+            sys.exit(0)
+
         thisid = config.nextid
         basedir = dir_for_trans(thisid)
         shell('mkdir', basedir)