From 9c5d9ad5b6e90a7b344dd76643ed374b4e45cd9a Mon Sep 17 00:00:00 2001 From: Ludovic Pouzenc Date: Sun, 2 Dec 2018 21:53:03 +0100 Subject: Don't skip whole dir if one stat() fails --- pidu | 30 ++++++++++++++++++------------ 1 file 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) -- cgit v1.2.3