[24058] in Source-Commits
/svn/athena r23661 - in trunk/athena/bin/delete: . debian
daemon@ATHENA.MIT.EDU (Evan Broder)
Sun Mar 29 15:56:12 2009
X-Barracuda-Envelope-From: broder@mit.edu
Date: Sun, 29 Mar 2009 15:55:43 -0400
From: Evan Broder <broder@MIT.EDU>
Message-Id: <200903291955.n2TJtho5009208@drugstore.mit.edu>
To: source-commits@mit.edu
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Author: broder
Date: 2009-03-29 15:55:43 -0400 (Sun, 29 Mar 2009)
New Revision: 23661
Modified:
trunk/athena/bin/delete/configure.in
trunk/athena/bin/delete/debian/changelog
trunk/athena/bin/delete/directories.c
trunk/athena/bin/delete/directories.h
trunk/athena/bin/delete/expunge.c
trunk/athena/bin/delete/lsdel.c
Log:
In delete:
* Apply patches from jik:
- When printing an amount of space, print it in friendly units, e.g.,
KB, MB or GB, rather than always printing kb.
Modified: trunk/athena/bin/delete/configure.in
===================================================================
--- trunk/athena/bin/delete/configure.in 2009-03-29 19:55:42 UTC (rev 23660)
+++ trunk/athena/bin/delete/configure.in 2009-03-29 19:55:43 UTC (rev 23661)
@@ -4,6 +4,8 @@
AC_PROG_CC
AC_PROG_INSTALL
+AC_CHECK_LIB([m], [log10])
+
ATHENA_UTIL_COM_ERR
ATHENA_AFS("-lsys -lrx -llwp -lsys -lafsutil")
Modified: trunk/athena/bin/delete/debian/changelog
===================================================================
--- trunk/athena/bin/delete/debian/changelog 2009-03-29 19:55:42 UTC (rev 23660)
+++ trunk/athena/bin/delete/debian/changelog 2009-03-29 19:55:43 UTC (rev 23661)
@@ -6,8 +6,10 @@
confused
- Change the ENOMATCH error constant to DELETE_ENOMATCH to avoid
conflicting with a system error constant of the same name
+ - When printing an amount of space, print it in friendly units, e.g.,
+ KB, MB or GB, rather than always printing kb.
- -- Evan Broder <broder@mit.edu> Sun, 29 Mar 2009 14:55:58 -0400
+ -- Evan Broder <broder@mit.edu> Sun, 29 Mar 2009 14:58:43 -0400
debathena-delete (10.0.0-0debathena1) unstable; urgency=low
Modified: trunk/athena/bin/delete/directories.c
===================================================================
--- trunk/athena/bin/delete/directories.c 2009-03-29 19:55:42 UTC (rev 23660)
+++ trunk/athena/bin/delete/directories.c 2009-03-29 19:55:43 UTC (rev 23661)
@@ -13,6 +13,7 @@
static char rcsid_directories_c[] = "$Id: directories.c,v 1.28 1999-01-22 23:08:54 ghudson Exp $";
#endif
+#include <math.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/param.h>
@@ -706,3 +707,38 @@
*in_strings = strings;
return 0;
}
+
+char *bytes_to_friendly(off_t bytes)
+{
+ double size = bytes;
+ char *output;
+
+ size /= 1024;
+ if (size < 1024) {
+ if (! (output = malloc(7))) {
+ set_error(errno);
+ error("malloc");
+ return "";
+ }
+ sprintf(output, "%.0fKB", ceil(size));
+ return(output);
+ }
+ size /= 1024;
+ if (size < 1024) {
+ if (! (output = malloc(9))) {
+ set_error(errno);
+ error("malloc");
+ return "";
+ }
+ sprintf(output, "%.1fMB", size);
+ return(output);
+ }
+ size /= 1024;
+ if (! (output = malloc((int)log10(size)+6))) {
+ set_error(errno);
+ error("malloc");
+ return "";
+ }
+ sprintf(output, "%.2fGB", size);
+ return(output);
+}
Modified: trunk/athena/bin/delete/directories.h
===================================================================
--- trunk/athena/bin/delete/directories.h 2009-03-29 19:55:42 UTC (rev 23660)
+++ trunk/athena/bin/delete/directories.h 2009-03-29 19:55:43 UTC (rev 23661)
@@ -15,10 +15,13 @@
#define True (Boolean) 1
#define False (Boolean) 0
+char *bytes_to_friendly(off_t);
#define specs_to_space(x) ((x).st_blocks)
#define space_to_k(x) ((x) / 2 + (((x) % 2) ? 1 : 0))
#define specs_to_k(x) space_to_k((x).st_blocks)
+#define space_to_friendly(x) bytes_to_friendly((x))
+#define specs_to_friendly(x) space_to_friendly((x).st_size)
#define FOLLOW_LINKS 1
#define DONT_FOLLOW_LINKS 0
Modified: trunk/athena/bin/delete/expunge.c
===================================================================
--- trunk/athena/bin/delete/expunge.c 2009-03-29 19:55:42 UTC (rev 23660)
+++ trunk/athena/bin/delete/expunge.c 2009-03-29 19:55:43 UTC (rev 23661)
@@ -263,11 +263,12 @@
}
}
if (yield) {
- if (noop)
- printf("Total that would be expunged: %dk\n",
- space_to_k(space_removed));
- else
- printf("Total expunged: %dk\n", space_to_k(space_removed));
+ char *friendly = space_to_friendly(space_removed);
+ if (noop)
+ printf("Total that would be expunged: %s\n", friendly);
+ else
+ printf("Total expunged: %s\n", friendly);
+ free(friendly);
}
return status;
}
@@ -375,8 +376,9 @@
(void) convert_to_user_name(real, user);
if (interactive) {
- printf ("%s: Expunge %s (%dk)? ", whoami, user,
- specs_to_k(file_ent->specs));
+ char *friendly = specs_to_friendly(file_ent->specs);
+ printf ("%s: Expunge %s (%s)? ", whoami, user, friendly);
+ free(friendly);
if (! yes()) {
set_status(EXPUNGE_NOT_EXPUNGED);
return error_code;
@@ -385,9 +387,12 @@
if (noop) {
space_removed += specs_to_space(file_ent->specs);
- printf("%s: %s (%dk) would be expunged (%dk total)\n", whoami, user,
- specs_to_k(file_ent->specs),
- space_to_k(space_removed));
+ char *friendly = space_to_friendly(space_removed);
+ char *friendly2 = specs_to_friendly(file_ent->specs);
+ printf("%s: %s (%s) would be expunged (%s total)\n", whoami, user,
+ friendly2, friendly);
+ free(friendly);
+ free(friendly2);
return 0;
}
@@ -397,10 +402,14 @@
status = unlink(real);
if (! status) {
space_removed += specs_to_space(file_ent->specs);
- if (verbose)
- printf("%s: %s (%dk) expunged (%dk total)\n", whoami, user,
- specs_to_k(file_ent->specs),
- space_to_k(space_removed));
+ if (verbose) {
+ char *friendly = space_to_friendly(space_removed);
+ char *friendly2 = specs_to_friendly(file_ent->specs);
+ printf("%s: %s (%s) expunged (%s total)\n", whoami, user,
+ friendly2, friendly);
+ free(friendly);
+ free(friendly2);
+ }
return 0;
}
else {
Modified: trunk/athena/bin/delete/lsdel.c
===================================================================
--- trunk/athena/bin/delete/lsdel.c 2009-03-29 19:55:42 UTC (rev 23660)
+++ trunk/athena/bin/delete/lsdel.c 2009-03-29 19:55:43 UTC (rev 23661)
@@ -205,10 +205,12 @@
return error_code;
}
}
- if (yield)
- printf("\nTotal space taken up by file%s: %dk\n",
- (total == 1 ? "" : "s"), space_to_k(space_total));
-
+ if (yield) {
+ char *friendly = space_to_friendly(space_total);
+ printf("\nTotal space taken up by file%s: %s\n",
+ (total == 1 ? "" : "s"), friendly);
+ free(friendly);
+ }
return status;
}