diff options
author | Lars Wirzenius <liw@liw.fi> | 2010-01-01 03:16:41 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2010-01-01 03:16:41 +0200 |
commit | eb85c7df4fcbeff0c28aeaa9329731dda9aace12 (patch) | |
tree | 57e3f17305803ae22cb54c29025d860ae1a812fb | |
parent | 2220cc038941de88a26b981e797c091f7869e8d5 (diff) | |
download | summain-eb85c7df4fcbeff0c28aeaa9329731dda9aace12.tar.gz |
Fix SHA-1 computation so it is only done for regular
files.
-rw-r--r-- | summainlib.py | 4 | ||||
-rw-r--r-- | summainlib_tests.py | 4 |
2 files changed, 7 insertions, 1 deletions
diff --git a/summainlib.py b/summainlib.py index 509bc50..ad6fee0 100644 --- a/summainlib.py +++ b/summainlib.py @@ -18,6 +18,7 @@ import grp import hashlib import os import pwd +import stat import time import urllib @@ -50,7 +51,8 @@ class FilesystemObject(object): self['Username'] = self.lookup_username(stat_result.st_uid) self['Gid'] = '%d' % stat_result.st_gid self['Group'] = self.lookup_group(stat_result.st_gid) - self['Sha-1'] = self.compute_sha1(filename, sha1) + if stat.S_ISREG(stat_result.st_mode): + self['Sha-1'] = self.compute_sha1(filename, sha1) def format_time(self, timestamp): return time.strftime('%Y-%m-%d %H:%M:%S +0000', diff --git a/summainlib_tests.py b/summainlib_tests.py index a3553ca..cbfb11c 100644 --- a/summainlib_tests.py +++ b/summainlib_tests.py @@ -108,3 +108,7 @@ class FilesystemObjectTests(unittest.TestCase): def test_formats_sha1_correctly_for_regular_file(self): self.assertEqual(self.new('foo')['Sha-1'], 'abc') + def test_formats_sha1_correctly_for_special_file(self): + self.st.st_mode = stat.S_IFDIR | 0755 + self.assertEqual(self.new('foo')['Sha-1'], '') + |