From 181332ffb439175edd950e404f90d4285dc22b1a Mon Sep 17 00:00:00 2001 From: Hrvoje Spoljar Date: Fri, 7 Nov 2014 16:06:10 +0100 Subject: [PATCH] Make sure we are measuring a real file file(f,'r') can't open socket and will fail if it encounters one there are likely other file types which can't be opened and would lead to failure --- scripts/python_fincore | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/scripts/python_fincore b/scripts/python_fincore index 37a7e1e..f44ffb8 100755 --- a/scripts/python_fincore +++ b/scripts/python_fincore @@ -96,14 +96,15 @@ def main(): for (path, dirs, files) in os.walk(options.directory): for myfile in files: f = os.path.join(path,myfile) - fd = file(f,'r') - file_size = os.fstat(fd.fileno())[stat.ST_SIZE] - if file_size == 0: + if os.path.isfile(f): + fd = file(f,'r') + file_size = os.fstat(fd.fileno())[stat.ST_SIZE] + if file_size == 0: + fd.close() + continue + pages_cached, pages_total = ftools.fincore_ratio(fd.fileno()) fd.close() - continue - pages_cached, pages_total = ftools.fincore_ratio(fd.fileno()) - fd.close() - rows.append([f, file_size, pages_total, pages_cached, (pages_cached * page_size), (float(pages_cached) / float(pages_total)) * 100.0]) + rows.append([f, file_size, pages_total, pages_cached, (pages_cached * page_size), (float(pages_cached) / float(pages_total)) * 100.0]) for f in args: fd = file(f, 'r')