summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLudovic Pouzenc <ludovic@pouzenc.fr>2018-12-02 21:53:03 +0100
committerLudovic Pouzenc <ludovic@pouzenc.fr>2018-12-02 21:53:03 +0100
commit9c5d9ad5b6e90a7b344dd76643ed374b4e45cd9a (patch)
treea88c1c4df8ec97191130a1132392ea3dc330add0
parent6b6ab3b0ea7d2c0a75222bff2d2d42712e021e23 (diff)
downloadpidu-9c5d9ad5b6e90a7b344dd76643ed374b4e45cd9a.tar.gz
pidu-9c5d9ad5b6e90a7b344dd76643ed374b4e45cd9a.tar.bz2
pidu-9c5d9ad5b6e90a7b344dd76643ed374b4e45cd9a.zip
Don't skip whole dir if one stat() failsHEADmaster
-rwxr-xr-xpidu30
1 files changed, 18 insertions, 12 deletions
diff --git a/pidu b/pidu
index 52ce2f2..1f5bece 100755
--- a/pidu
+++ b/pidu
@@ -2,6 +2,11 @@
import sys, os, argparse
from multiprocessing import Process, JoinableQueue, Queue, cpu_count
+# Don't display big traceback on file permission problems and so
+def exc_oneline():
+ (exception_type, exception, traceback) = sys.exc_info()
+ print("%s: %s" % (exception_type.__name__, exception), file=sys.stderr)
+
# Forked process main proc
def proc_du(q_in,counters_count, q_out):
# Sum up all files' 512-byte blocks allocated
@@ -12,19 +17,20 @@ def proc_du(q_in,counters_count, q_out):
if special == 'done':
break
try:
- for it in os.scandir(path):
- # Sum up file or folder physicial size (in blocks) to local_counters
- local_counters[counter_indice] += it.stat(follow_symlinks=False).st_blocks
- # Put more work on queue (could be taken by an other process)
- if it.is_dir(follow_symlinks=False):
- q_in.put( (it.path, counter_indice, None) )
+ for entry in os.scandir(path):
+ try:
+ # Sum up file or folder physicial size (in blocks) to local_counters
+ local_counters[counter_indice] += entry.stat(follow_symlinks=False).st_blocks
+ # Put more work on queue (could be taken by an other process)
+ if entry.is_dir(follow_symlinks=False):
+ q_in.put( (entry.path, counter_indice, None) )
+ except:
+ exc_oneline()
except:
- # Don't display big traceback on file permission problems and so
- (exception_type, exception, traceback) = sys.exc_info()
- print("%s: %s" % (exception_type.__name__, exception), file=sys.stderr)
- finally:
- # Go next file or folder even if current can't be treated
- q_in.task_done()
+ exc_oneline()
+
+ # Go next file or folder even if current can't be treated
+ q_in.task_done()
# After receiving special 'done' message, put results back into q_out
q_out.put(local_counters)