svn commit: trunk/busybox: coreutils libbb
vda at busybox.net
vda at busybox.net
Fri Jun 13 21:28:42 PDT 2008
Author: vda
Date: 2008-06-13 21:28:41 -0700 (Fri, 13 Jun 2008)
New Revision: 22331
Log:
dos2unix: do not destroy symlinks and mode of the file being converted.
Modified:
trunk/busybox/coreutils/dos2unix.c
trunk/busybox/libbb/xreadlink.c
Changeset:
Modified: trunk/busybox/coreutils/dos2unix.c
===================================================================
--- trunk/busybox/coreutils/dos2unix.c 2008-06-13 20:49:35 UTC (rev 22330)
+++ trunk/busybox/coreutils/dos2unix.c 2008-06-14 04:28:41 UTC (rev 22331)
@@ -24,24 +24,27 @@
{
FILE *in, *out;
int i;
- char *name_buf = name_buf; /* for compiler */
+ char *temp_fn = temp_fn; /* for compiler */
+ char *resolved_fn = resolved_fn;
in = stdin;
out = stdout;
if (fn != NULL) {
- in = xfopen(fn, "r");
- /*
- The file is then created with mode read/write and
- permissions 0666 for glibc 2.0.6 and earlier or
- 0600 for glibc 2.0.7 and later.
- */
- name_buf = xasprintf("%sXXXXXX", fn);
- i = mkstemp(name_buf);
+ struct stat st;
+
+ resolved_fn = xmalloc_follow_symlinks(fn);
+ if (resolved_fn == NULL)
+ bb_simple_perror_msg_and_die(fn);
+ in = xfopen(resolved_fn, "r");
+ fstat(fileno(in), &st);
+
+ temp_fn = xasprintf("%sXXXXXX", resolved_fn);
+ i = mkstemp(temp_fn);
if (i == -1
- || fchmod(i, 0600) == -1
+ || fchmod(i, st.st_mode) == -1
|| !(out = fdopen(i, "w+"))
) {
- bb_perror_nomsg_and_die();
+ bb_simple_perror_msg_and_die(temp_fn);
}
}
@@ -56,12 +59,12 @@
if (fn != NULL) {
if (fclose(in) < 0 || fclose(out) < 0) {
- unlink(name_buf);
+ unlink(temp_fn);
bb_perror_nomsg_and_die();
}
-// TODO: destroys symlinks. See how passwd handles this
- xrename(name_buf, fn);
- free(name_buf);
+ xrename(temp_fn, resolved_fn);
+ free(temp_fn);
+ free(resolved_fn);
}
}
Modified: trunk/busybox/libbb/xreadlink.c
===================================================================
--- trunk/busybox/libbb/xreadlink.c 2008-06-13 20:49:35 UTC (rev 22330)
+++ trunk/busybox/libbb/xreadlink.c 2008-06-14 04:28:41 UTC (rev 22331)
@@ -54,7 +54,6 @@
goto jump_in;
while (1) {
-
linkpath = xmalloc_readlink(buf);
if (!linkpath) {
/* not a symlink, or doesn't exist */
More information about the busybox-cvs
mailing list