Skip to content

Commit

Permalink
Revise rules for clobbering directories
Browse files Browse the repository at this point in the history
In general, make directories behave like files:

1. Don't clobber a directory we don't know about.

2. Do clobber a directory if we do know about it.

This revises the behavior described in the following commits:

(1) commit f657dea
(2) commit 29925fe

I think it is a better solution to the problem mentioned in commit (1).
In particular, if we manually create a directory foo and then later try
to run foo.do, redo will warn that foo exists and is not generated, and
will not clobber the directory -- just as for a file.

Note that the distinction between files and directories mentioned in the
log for commit (1) (i.e., redo doesn't know about directories in the
same way as it knows about files) seems to be true of the original redo
implementation, but not intrinsic to the problem. I erased this
distinction.
  • Loading branch information
bocchino committed Aug 1, 2018
1 parent 29925fe commit 434da58
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions lib/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Build redo targets
# ======================================================================

import sys, os, errno, stat, re
import sys, os, errno, stat
import vars, jobs, state, targets_seen, deps
from helpers import remove, rename, close_on_exec, join
from log import log, log_, debug, debug2, err, warn
Expand Down Expand Up @@ -169,8 +169,7 @@ def _start_do(self):
sf.set_checked()
sf.save()
return self._after2(0)
if (os.path.exists(t) and not os.path.isdir(t + '/.')
and not sf.is_generated):
if (os.path.exists(t) and not sf.is_generated):
# an existing source file that was not generated by us.
# This step is mentioned by djb in his notes.
# For example, a rule called default.c.do could be used to try
Expand Down Expand Up @@ -352,17 +351,12 @@ def _after2(self, rv):
# ----------------------------------------------------------------------

def _remove(path):
redo_tmp = re.search('\.redo.\.tmp', path)
if not redo_tmp and os.path.isdir(path) and len(os.listdir(path)) > 0:
warn('directory %s is nonempty; not redoing\n' % _nice(path))
return False
else:
try:
remove(path)
except:
err('failed attempting to remove %s\n' % _nice(path))
raise
return True
try:
remove(path)
except:
err('failed attempting to remove %s\n' % _nice(path))
raise
return True


def _rename(src, dest):
Expand Down

0 comments on commit 434da58

Please sign in to comment.