|
From: | GNU bug Tracking System |
Subject: | [debbugs-tracker] bug#22769: closed (In-place sorting of a file) |
Date: | Tue, 23 Feb 2016 07:54:01 +0000 |
Your message dated Mon, 22 Feb 2016 23:53:25 -0800 with message-id <address@hidden> and subject line Re: bug#22769: In-place sorting of a file has caused the debbugs.gnu.org bug report #22769, regarding In-place sorting of a file to be marked as done. (If you believe you have received this mail in error, please contact address@hidden) -- 22769: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=22769 GNU Bug Tracking System Contact address@hidden with problems
--- Begin Message ---Subject: In-place sorting of a file Date: Mon, 22 Feb 2016 04:57:54 -0500
Hi,I found someone talking about sorting a file in-place:http://stackoverflow.com/questions/9117274/do-i-need-to-generate-a-second-file-to-sort-a-fileHowever, sort file.txt -o file.txt is NOT safe. A strace sequence (sorting 1 2 3 4 5):read(3, "1\n2\n3\n4\n5\n\n", 4096) = 11read(3, "", 4096) = 0_llseek(3, 0, [11], SEEK_CUR) = 0close(3) = 0munmap(0xb7743000, 4096) = 0ftruncate64(1, 0) = 0 <---------------------- (*)fstat64(1, {st_mode=S_IFREG|0664, st_size=0, ...}) = 0mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7743000write(1, "\n1\n2\n3\n4\n5\n", 11) = 11close(1) = 0If at this time, the system crashes (or later at write), the data is gone forever (or have a suffering recovery). Should we warn users of this, or add special treatment with this case (write a temp file and rename it)?Thank your for your attention.Regards,Yanyan Jiang 蒋炎岩Institute of Computer Software,Dept. of Computer Science, Nanjing University
--- End Message ---
--- Begin Message ---Subject: Re: bug#22769: In-place sorting of a file Date: Mon, 22 Feb 2016 23:53:25 -0800 User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.5.1 Yanyan Jiang wrote:If at this time, the system crashes (or later at write), the data is gone forever (or have a suffering recovery). Should we warn users of this, or add special treatment with this case (write a temp file and rename it)?Thanks for reporting the issue. Writing to a temp file and renaming would have problems, as it might change the file's ownership or permissions or etc., and also won't behave as the user expects if the file has multiple hard links. We should at least warn users about the problem in the documentation, though, so I installed the attached patch on Savannah at:http://git.savannah.gnu.org/cgit/coreutils.git/commit/?id=4c1995f1b673b0e1eae73a9db4e28016b86dee9e0001-doc-document-sort-o-F-F-danger.txt
Description: Text document
--- End Message ---
[Prev in Thread] | Current Thread | [Next in Thread] |