From 87398fde457aab2082f3c07678f35004e19569be Mon Sep 17 00:00:00 2001 From: Michael Forney Date: Mon, 3 Oct 2022 05:34:48 +0000 Subject: patch: fix deletion of files If we are deleting a file, we do not want to attempt to create an empty /dev/null.tmp$pid. finish() doesn't look at tmp for deletions during a successful run, so leave it set to nil. On a failure, guard tmp removal on tmp != nil. --- sys/src/cmd/patch.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'sys/src/cmd/patch.c') diff --git a/sys/src/cmd/patch.c b/sys/src/cmd/patch.c index 11eb70c14..394f4bfc0 100644 --- a/sys/src/cmd/patch.c +++ b/sys/src/cmd/patch.c @@ -393,12 +393,11 @@ blat(char *old, char *new, char *o, usize len) char *tmp; int fd; - if(strcmp(new, "/dev/null") == 0 && len != 0){ - sysfatal("diff modifies removed file"); - return; - } tmp = nil; - if(!dryrun){ + if(strcmp(new, "/dev/null") == 0){ + if(len != 0) + sysfatal("diff modifies removed file"); + }else if(!dryrun){ if(mkpath(new) == -1) sysfatal("mkpath %s: %r", new); if((tmp = smprint("%s.tmp%d", new, getpid())) == nil) @@ -428,7 +427,7 @@ finish(int ok) for(i = 0; i < nchanged; i++){ c = &changed[i]; if(!ok){ - if(remove(c->tmp) == -1) + if(c->tmp != nil && remove(c->tmp) == -1) fprint(2, "remove %s: %r\n", c->tmp); goto Free; } -- cgit v1.2.3