brushtechnology / fabricate

The better build tool. Finds dependencies automatically for any language.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

AtimesRunner traverses symlinks

GoogleCodeExporter opened this issue · comments

What steps will reproduce the problem?
1. Make a build.py that uses fabricate to make a python virtualenv and forces 
use of atime_runner
2. be root
3. do 'python build.py build clean' and watch your 
/usr/lib/python2.7/config/Makefile (among other things) get deleted by the 
'clean'

What is the expected output? What do you see instead?

It shouldn't be deleted as it's not created.


What version of the product are you using? On what operating system?

latest stock fabricate.py

Please provide any additional information below.

The issue is that virtualenv makes a symlink to /usr/lib/python2.7/config/, 
which is this (incorrectly!) traversed by _file_times() in AtimeRunner.
The following patch fixes it:

diff --git a/fabricate.py b/fabricate.py
index ed8235b..e9c353e 100644
--- a/fabricate.py
+++ b/fabricate.py
@@ -353,11 +353,11 @@ class AtimesRunner(Runner):
                 fullname = name
             else:
                 fullname = os.path.join(path, name)
-            st = os.stat(fullname)
+            st = os.lstat(fullname)
             if stat.S_ISDIR(st.st_mode):
                 if depth > 1:
                     times.update(self._file_times(fullname, depth-1))
-            elif stat.S_ISREG(st.st_mode):
+            elif stat.S_ISREG(st.st_mode) or stat.S_ISLNK(st.st_mode):
                 times[fullname] = st.st_atime, st.st_mtime
         return times

Note that this is especially problematic on MacOS where the user running 
fabricate also quite likely is the owner of the lib/python../config/Makefile ; 
average linux users are protected by the fact that they don't own that file and 
so can't delete it.

Original issue reported on code.google.com by pjimen...@gmail.com on 12 Jun 2013 at 12:34

Here's the issue where pjz and I wrestled with this:

https://github.com/gittip/aspen-python/issues/190

I don't think it's problematic for Mac OS in general because most people are 
probably using the system Python, which would be protected. I have my own 
Python install in ~, which is why this presented for me.

Original comment by whit537@gmail.com on 12 Jun 2013 at 12:37

  • Added labels: ****
  • Removed labels: ****
Traversing symlinks also breaks the build in the middle when there are any 
dangling symlinks.

Original comment by nuutti.k...@gmail.com on 6 Jul 2013 at 5:56

  • Added labels: ****
  • Removed labels: ****