Re: Can't hardlink in different dirs. (BUG#826)

Peter Samuelson (peter@wire.cadcamlab.org)
10 Dec 1999 07:31:52 -0600


[Pavel Machek <pavel@suse.cz>]
> I still think that adding feature to truncate file before deletion
> into rm would make you happy, Andrea. That handles both open() and
> link() cases nicely.

I agree. Something like this? (Lightly tested.)

Peter

diff -urN fileutils-4.0/src.orig/mv.c fileutils-4.0/src/mv.c
--- fileutils-4.0/src.orig/mv.c Fri Dec 10 06:50:32 1999
+++ fileutils-4.0/src/mv.c Fri Dec 10 06:47:33 1999
@@ -110,6 +110,7 @@
part is enough. It implies removal. */
x->interactive = 0;
x->stdin_tty = 0;
+ x->truncate = 0;

x->verbose = 0;
}
diff -urN fileutils-4.0/src.orig/remove.c fileutils-4.0/src/remove.c
--- fileutils-4.0/src.orig/remove.c Tue Nov 3 20:58:20 1998
+++ fileutils-4.0/src/remove.c Fri Dec 10 07:25:44 1999
@@ -647,6 +647,23 @@
if (x->verbose)
printf (_("removing %s\n"), full_filename (pathname));

+ if (x->truncate && S_ISREG (fspec_filetype_mode (fs)))
+ {
+ int e = euidaccess (pathname, W_OK);
+ if (e && chmod (pathname, S_IWUSR))
+ {
+ error (0, errno, _("cannot chmod `%s'"), full_filename (pathname));
+ return RM_ERROR;
+ }
+ if (truncate (pathname, 0))
+ {
+ error (0, errno, _("cannot truncate `%s'"), full_filename (pathname));
+ return RM_ERROR;
+ }
+ if (e)
+ chmod (pathname, fspec_filetype_mode (fs));
+ }
+
if (unlink (pathname) && (errno != ENOENT || !x->ignore_missing_files))
{
error (0, errno, _("cannot unlink `%s'"), full_filename (pathname));
diff -urN fileutils-4.0/src.orig/remove.h fileutils-4.0/src/remove.h
--- fileutils-4.0/src.orig/remove.h Tue Jan 20 18:09:05 1998
+++ fileutils-4.0/src/remove.h Fri Dec 10 06:28:23 1999
@@ -10,6 +10,9 @@
/* If nonzero, recursively remove directories. */
int recursive;

+ /* If nonzero, truncate files before removing them. */
+ int truncate;
+
/* If nonzero, stdin is a tty. */
int stdin_tty;

diff -urN fileutils-4.0/src.orig/rm.c fileutils-4.0/src/rm.c
--- fileutils-4.0/src.orig/rm.c Fri Dec 10 06:24:57 1999
+++ fileutils-4.0/src/rm.c Fri Dec 10 06:44:12 1999
@@ -72,6 +72,7 @@
{"force", no_argument, NULL, 'f'},
{"interactive", no_argument, NULL, 'i'},
{"recursive", no_argument, NULL, 'r'},
+ {"truncate", no_argument, NULL, 'T'},
{"verbose", no_argument, NULL, 'v'},
{"help", no_argument, &show_help, 1},
{"version", no_argument, &show_version, 1},
@@ -94,6 +95,7 @@
-f, --force ignore nonexistent files, never prompt\n\
-i, --interactive prompt before any removal\n\
-r, -R, --recursive remove the contents of directories recursively\n\
+ -T, --truncate truncate file before removing\n\
-v, --verbose explain what is being done\n\
--help display this help and exit\n\
--version output version information and exit\n\
@@ -111,6 +113,7 @@
x->ignore_missing_files = 0;
x->interactive = 0;
x->recursive = 0;
+ x->truncate = 0;
x->stdin_tty = isatty (STDIN_FILENO);
x->verbose = 0;
}
@@ -129,7 +132,7 @@

rm_option_init (&x);

- while ((c = getopt_long (argc, argv, "dfirvR", long_opts, NULL)) != -1)
+ while ((c = getopt_long (argc, argv, "dfirvRT", long_opts, NULL)) != -1)
{
switch (c)
{
@@ -149,6 +152,9 @@
case 'r':
case 'R':
x.recursive = 1;
+ break;
+ case 'T':
+ x.truncate = 1;
break;
case 'v':
x.verbose = 1;

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/