We might stat() the file and get some size, but by the time
we readlink() the link has changed and the size is something
else.
Arguably, we can't really avoid races here if we don't have
a consistent snapshot of the filesystem to save, however, in
this case we later get an assertion failure when the data is
read back from the index (or repo), and it's easy to avoid.
Set the size from the actually recorded symlink target.
Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
Reviewed-by: Rob Browning <rlb@defaultvalue.org>
Tested-by: Rob Browning <rlb@defaultvalue.org>
try:
if stat.S_ISLNK(st.st_mode):
self.symlink_target = os.readlink(path)
+ # might have read a different link than the
+ # one that was in place when we did stat()
+ self.size = len(self.symlink_target)
except OSError as e:
add_error('readlink: %s' % e)