nicolas / debian.moreutils (public) (License: GPL-2, GPL-2+, Expat, BSD-2-Clause, Public Domain) (since 2018-09-25) (hash sha1)
Debian packaging of joeyh's moreutils
List of commits:
Subject Hash Author Date (UTC)
more fixes to tempfile writeback a580bbd17850753746d6d1a2b65817edaf4485c9 Joey Hess 2008-04-11 22:27:40
set umask before calling mkstemp 0595609018095dabd5d1a56cf03ddcc008a9e928 Joey Hess 2008-04-11 21:47:28
update physmem copyright 30746c4357c0ac6110ca7e2a279ce9e82e879581 Joey Hess 2008-04-11 21:44:19
fix two bugs writing the output file 6fa7d9907e7211f06656b296940aaca1d6b4d1df Joey Hess 2008-04-11 21:42:38
move code into a function dcb580b3998a19b112004f23298490a34af59fc8 Joey Hess 2008-04-11 20:15:29
fix edge cases ee4e74dd6a20706f29ef30a2613a1977f6f325fa Joey Hess 2008-04-11 20:10:18
reorder defines 0bf88ea14cda6e6e57e97356862628ae49269c8a Joey Hess 2008-04-11 19:54:30
set up signal handlers before creating temp file 0ff304e2ca860e51e75bbfc08290e364e94cb32e Joey Hess 2008-04-11 19:53:38
another round of whitespace fixes c391b00d2837d1571ac1d361551378adf19ae83f Joey Hess 2008-04-11 19:50:47
remove debug 919ce1f7b6d80dfdc3c613f898215962985f9c66 Brock Noland 2008-04-11 19:22:39
sponge fixes 42c5c5a799502743307b392bf9e7c0205ef85ace Brock Noland 2008-04-11 18:16:09
better usage message 73327f97a62619cb8b1a0bc03e5e105839449f9a Joey Hess 2008-04-11 04:36:46
update changelog 79c6fe1242a4747c4adbcc9030d2cadc61c1028a Joey Hess 2008-04-11 04:35:24
convert to new format 2c8be0fef4c247de0e5511abdbda25e3611b9f8c Joey Hess 2008-04-11 04:32:31
first pass thru the code b2174f2df2410bf82fe646bcedd333ddbd7dbf66 Joey Hess 2008-04-11 03:49:31
make sponge use a temp file if the input is large 866dfb32b3ba7d0be153608b28dd9f461986251d Joey Hess 2008-04-11 03:28:15
sponge, ifne: Ensure that suspending/resuming doesn't result in partial writes of the data, by using fwrite() rather than write(). ddcbf562e3b6bb3a4441cc640c756127be4cf26b Joey Hess 2008-04-10 18:11:21
sponge: Ensure that suspending/resuming doesn't result in partial writes of the data, by using fwrite() rather than write(). 71349b5ae83878f4e59fc6517976998150856933 Joey Hess 2008-04-10 18:05:25
Add ifne, contributed by Javier Merino. 2fbf7a9636fae8012298901e98e63cc1b32745ee Joey Hess 2008-03-20 16:57:08
Moreutils: Added ifne 752a84ae61dd1c37dec9a1cb0d30e8c27db1994a Javier Merino 2008-03-20 12:03:26
Commit a580bbd17850753746d6d1a2b65817edaf4485c9 - more fixes to tempfile writeback
Avoid overwriting symlinks with the temp file.

When renaming the temp file, restore the original file's permissions after.
Author: Joey Hess
Author date (UTC): 2008-04-11 22:27
Committer name: Joey Hess
Committer date (UTC): 2008-04-11 22:27
Parent(s): 0595609018095dabd5d1a56cf03ddcc008a9e928
Signer:
Signing key:
Signing status: N
Tree: 22dc2f7c4f296c19b33471edfcaa491b5a7660ac
File Lines added Lines deleted
sponge.c 33 21
File sponge.c changed (mode: 100644) (index dcd4aba..a02e0e7)
... ... static void write_buff_out(char* buff, size_t length, FILE *fd) {
199 199 } }
200 200 } }
201 201
202 static void copy_tmpfile(FILE *tmpfile, FILE *outfd) {
202 static void copy_tmpfile(FILE *tmpfile, FILE *outfile) {
203 203 char buf[BUFF_SIZE]; char buf[BUFF_SIZE];
204 204 if (fseek(tmpfile, 0, SEEK_SET)) { if (fseek(tmpfile, 0, SEEK_SET)) {
205 205 perror("could to seek to start of temporary file"); perror("could to seek to start of temporary file");
 
... ... static void copy_tmpfile(FILE *tmpfile, FILE *outfd) {
207 207 exit(1); exit(1);
208 208 } }
209 209 while (fread(buf, BUFF_SIZE, 1, tmpfile) > 0) { while (fread(buf, BUFF_SIZE, 1, tmpfile) > 0) {
210 write_buff_out(buf, BUFF_SIZE, outfd);
210 write_buff_out(buf, BUFF_SIZE, outfile);
211 211 } }
212 212 if (ferror(tmpfile)) { if (ferror(tmpfile)) {
213 213 perror("read temporary file"); perror("read temporary file");
 
... ... static void copy_tmpfile(FILE *tmpfile, FILE *outfd) {
215 215 exit(1); exit(1);
216 216 } }
217 217 fclose(tmpfile); fclose(tmpfile);
218 fclose(outfd);
218 fclose(outfile);
219 219 } }
220 220
221 221 FILE *open_tmpfile(void) { FILE *open_tmpfile(void) {
 
... ... int main (int argc, char **argv) {
247 247 char *buf, *bufstart, *outname = NULL; char *buf, *bufstart, *outname = NULL;
248 248 size_t bufsize = BUFF_SIZE; size_t bufsize = BUFF_SIZE;
249 249 size_t bufused = 0; size_t bufused = 0;
250 FILE *tmpfile = 0;
250 FILE *outfile, *tmpfile = 0;
251 251 ssize_t i = 0; ssize_t i = 0;
252 252 size_t mem_available = default_sponge_size(); size_t mem_available = default_sponge_size();
253 253
 
... ... int main (int argc, char **argv) {
293 293 /* write whatever we have in memory to tmpfile */ /* write whatever we have in memory to tmpfile */
294 294 if (bufused) if (bufused)
295 295 write_buff_tmp(bufstart, bufused, tmpfile); write_buff_tmp(bufstart, bufused, tmpfile);
296 fclose(tmpfile);
296 free(bufstart);
297 if (fflush(tmpfile) != 0) {
298 perror("fflush");
299 exit(1);
300 }
297 301
298 302 if (outname) { if (outname) {
299 303 /* If it's a regular file, or does not yet exist, /* If it's a regular file, or does not yet exist,
300 304 * attempt a fast rename of the temp file. */ * attempt a fast rename of the temp file. */
301 if ((stat(outname, &statbuf) == 0 &&
302 S_ISREG(statbuf.st_mode)) ||
303 errno == ENOENT) {
304 if (rename(tmpname, outname) != 0) {
305 /* Slow copy. */
306 FILE *outfd = fopen(outname, "w");
307 if (outfd < 0) {
308 perror("error opening output file");
309 exit(1);
310 }
311 copy_tmpfile(tmpfile, outfd);
305 if (((lstat(outname, &statbuf) == 0 &&
306 S_ISREG(statbuf.st_mode) &&
307 ! S_ISLNK(statbuf.st_mode)
308 ) || errno == ENOENT) &&
309 rename(tmpname, outname) == 0) {
310 /* Fix renamed file mode. */
311 if (errno != ENOENT &&
312 chmod(outname, statbuf.st_mode) != 0) {
313 perror("chmod");
314 exit(1);
312 315 } }
316 return(0);
317 }
318
319 /* Fall back to slow copy. */
320 outfile = fopen(outname, "w");
321 if (!outfile) {
322 perror("error opening output file");
323 exit(1);
313 324 } }
325 copy_tmpfile(tmpfile, outfile);
314 326 } }
315 327 else { else {
316 328 copy_tmpfile(tmpfile, stdout); copy_tmpfile(tmpfile, stdout);
317 329 } }
318 330 } }
319 331 else { else {
320 FILE *outfd = stdout;
332 outfile = stdout;
321 333 if (outname) { if (outname) {
322 outfd = fopen(outname, "w");
323 if (outfd < 0) {
334 outfile = fopen(outname, "w");
335 if (!outfile) {
324 336 perror("error opening output file"); perror("error opening output file");
325 337 exit(1); exit(1);
326 338 } }
327 339 } }
328 340 if (bufused) if (bufused)
329 write_buff_out(bufstart, bufused, outfd);
330 fclose(outfd);
341 write_buff_out(bufstart, bufused, outfile);
342 fclose(outfile);
331 343 } }
332 344
333 345 return 0; return 0;
Hints:
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://rocketgit.com/user/nicolas/debian.moreutils

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@ssh.rocketgit.com/user/nicolas/debian.moreutils

Clone this repository using git:
git clone git://git.rocketgit.com/user/nicolas/debian.moreutils

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a merge request:
... clone the repository ...
... make some changes and some commits ...
git push origin main