Bug 785 - Having identical sort input and output files does not work
Summary: Having identical sort input and output files does not work
Status: RESOLVED FIXED
Alias: None
Product: Busybox
Classification: Unclassified
Component: Other (show other bugs)
Version: 1.15.x
Hardware: PC Linux
: P5 enhancement
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-12-07 21:47 UTC by John Ata
Modified: 2009-12-13 01:01 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:


Attachments
Delay opening output file until input files are processed (832 bytes, patch)
2009-12-07 21:47 UTC, John Ata
Details

Note You need to log in before you can comment on or make changes to this bug.
Description John Ata 2009-12-07 21:47:04 UTC
Created attachment 811 [details]
Delay opening output file until input files are processed

In the busybox sort command, the output file is opened, truncated and presumably verified before the input files are read and sorted.  This causes problems when applications intend to sort a file on top of itself (e.g. ctags).  The provided patch delays the opening/truncation of the output file until after the input files are read and sorted.  This allows something like:
sort -o F F to sort file F putting the output into F.  This is consistent with the Linux sort command which for the most part does this as well.  This patch has been tested on an earlier version of busybox and appears to work well.
Comment 1 Denys Vlasenko 2009-12-13 01:01:37 UTC
Thanks!

Fixed in git, will be in 1.16.x