Re: ln overwrites newly created files

2007-08-23 Thread Jim Meyering
Jim Meyering <[EMAIL PROTECTED]> wrote:

> Eric Blake <[EMAIL PROTECTED]> wrote:
>
>> Contrast the following:
>>
>> $ mkdir a b c
>> $ echo 1 > a/f
>> $ echo 2 > b/f
>> $ cp -v a/f b/f c --remove-destination
>> `a/f' -> `c/f'
>> cp: will not overwrite just-created `c/f' with `b/f'
>>
>> with the similar:
>>
>> $ rm c/f
>> $ ln -vf a/f b/f c
>> `c/f' => `a/f'
>> `c/f' => `b/f'
>> $ cat c/f
>> 2
>>
>> Oops - we overwrote the just-created c/f with a link to b/f.  Similarly
>> with ln -s, where we lose the just-created link to a/f.
>
> Good catch.
> Fixing this is important to avoid loss that would otherwise happen like this:
>
>   ln -f a/f b/f c && rm -rf a b
>
> If ln succeeds, the user should be assured that removing the
> just-linked files is ok, since there should be hard links in c/.
> If ln exits successfully but leaves no link to one of the source
> files, then a user running the above will lose whatever is in "a/f".

Thanks for spotting that.
I've pushed this fix:

Don't let ln be a party to destroying user data.
* src/ln.c: Include "file-set.h", "hash.h" and "hash-triple.h".
(dest_set, DEST_INFO_INITIAL_CAPACITY): New globals.
(do_link): Refuse to remove a just-created link.
Record a name,dev,ino triple for each link we create.
(main): Initialize dest_set, if needed.
* tests/mv/childproof: Test for the above fix.
* NEWS: Document this.
Reported by Eric Blake.

Move functions from copy.c into new modules, since ln needs them, too.
* bootstrap.conf (gnulib_modules): Add file-set.
* gl/lib/file-set.c (record_file, seen_file): Functions from copy.c.
* gl/lib/file-set.h: Add prototypes.
* gl/lib/hash-triple.c (triple_hash, triple_hash_no_name):
(triple_compare, triple_free): Functions from copy.c.
* gl/lib/hash-triple.h (struct F_triple): Define.  From copy.c.
Add prototypes.
* gl/modules/file-set: New module.
* gl/modules/hash-triple: New module.
* src/Makefile.am (copy_sources): New variable.
(ginstall_SOURCES, cp_SOURCES, mv_SOURCES): Use it.
* src/copy.c: Include hash-triple.h.
No longer include hash-pjw.h.
(copy_internal): Don't pass a NULL third argument to record_file,
since that function no longer accepts that.
(record_file): Move this function to file-set.c.
Along the way, remove the code to allow a NULL stat-buffer pointer.
Adjust sole caller.
(seen_file): Move this function to file-set.c.
(struct F_triple): Move declaration to hash-triple.h.
(triple_compare, triple_free, triple_hash, triple_hash_no_name):
Move these functions to hash-triple.c.

-
commit d02e4e77753f580ab91afc5915333222edc82104
Author: Jim Meyering <[EMAIL PROTECTED]>
Date:   Thu Aug 23 11:51:01 2007 +0200

Don't let ln be a party to destroying user data.

* src/ln.c: Include "file-set.h", "hash.h" and "hash-triple.h".
(dest_set, DEST_INFO_INITIAL_CAPACITY): New globals.
(do_link): Refuse to remove a just-created link.
Record a name,dev,ino triple for each link we create.
(main): Initialize dest_set, if needed.
* tests/mv/childproof: Test for the above fix.
* NEWS: Document this.
Reported by Eric Blake.

Signed-off-by: Jim Meyering <[EMAIL PROTECTED]>

diff --git a/ChangeLog b/ChangeLog
index e20e96f..4947123 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
 2007-08-23  Jim Meyering  <[EMAIL PROTECTED]>

+   Don't let ln be a party to destroying user data.
+   * src/ln.c: Include "file-set.h", "hash.h" and "hash-triple.h".
+   (dest_set, DEST_INFO_INITIAL_CAPACITY): New globals.
+   (do_link): Refuse to remove a just-created link.
+   Record a name,dev,ino triple for each link we create.
+   (main): Initialize dest_set, if needed.
+   * tests/mv/childproof: Test for the above fix.
+   * NEWS: Document this.
+   Reported by Eric Blake.
+
Move functions from copy.c into new modules, since ln needs them, too.
* bootstrap.conf (gnulib_modules): Add file-set.
* gl/lib/file-set.c (record_file, seen_file): Functions from copy.c.
diff --git a/NEWS b/NEWS
index c548c0b..6a0f18d 100644
--- a/NEWS
+++ b/NEWS
@@ -56,6 +56,18 @@ GNU coreutils NEWS-*- 
outline -*-
   ptx longer accepts the --copyright option.
   who no longer accepts -i or --idle.

+** Improved robustness
+
+  ln -f can no longer silently clobber a just-created hard link.
+  In some cases, ln could be seen as being responsible for data loss.
+  For example, given directories a, b, c, and files a/f and b/f, we
+  should be able to do this safely: ln -f a/f b/f c && rm -f a/f b/f
+  However, before this change, ln would succeed, and thus cause the
+  loss of the contents of a/f.
+
+  stty no longer silently accepts certain invalid hex values

[bug #20883] sort -u -n drops more lines than expected

2007-08-23 Thread anonymous

URL:
  

 Summary: sort -u -n drops more lines than expected
 Project: GNU Core Utilities
Submitted by: None
Submitted on: Friday 08/24/2007 at 05:52 UTC
Category: None
Severity: 3 - Normal
  Item Group: None
  Status: None
 Privacy: Public
 Assigned to: None
 Open/Closed: Open
 Discussion Lock: Any

___

Details:

Given the following example input:

1   3
2   1
1   1
3   1
1   2
1   1

sort -u gives the expected output:

1   1
1   2
1   3
2   1
3   1

But sort -n -u drops all lines that match the sort column:

1   3
2   1
3   1

Or compare sort -n -u -k2:

2   1
1   2
1   3

It's not clear from the info page that this is the correct behavior, but I
would expect sort -n -u to do the same as sort -n  | uniq, or for this
omitting equal keys (instead of equal lines) to be more explicit in the
documentation.





___

Reply to this item at:

  

___
  Message sent via/by Savannah
  http://savannah.gnu.org/



___
Bug-coreutils mailing list
Bug-coreutils@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-coreutils