|
8 | 8 | from .exceptions import FileNotFoundError |
9 | 9 | try: |
10 | 10 | from queue import Empty # Python 3 |
| 11 | + import _thread |
11 | 12 | except ImportError: |
12 | 13 | from Queue import Empty # Python 2 |
| 14 | + import thread |
13 | 15 |
|
14 | 16 | WORKER_THREAD_PER_PROCESS = 50 |
15 | 17 | QUEUE_BUCKET_SIZE = 10 |
@@ -37,7 +39,7 @@ def monitor_exception(exception_queue, process_ids): |
37 | 39 | logger.log(logging.DEBUG, "Joining processes") |
38 | 40 | for p in process_ids: |
39 | 41 | p.join() |
40 | | - import thread |
| 42 | + |
41 | 43 | logger.log(logging.DEBUG, "Interrupting main") |
42 | 44 | raise Exception(local_exception) |
43 | 45 | except Empty: |
@@ -85,10 +87,13 @@ def walk(walk_path): |
85 | 87 | if files['type'] == 'DIRECTORY': |
86 | 88 | dir_processed_counter.increment() # A new directory to process |
87 | 89 | walk_thread_pool.submit(walk, files['name']) |
88 | | - paths.append(files['name']) |
| 90 | + |
| 91 | + paths.append((files['name'], files['type'] == 'FILE')) |
| 92 | + |
89 | 93 | if len(paths) == QUEUE_BUCKET_SIZE: |
90 | 94 | file_path_queue.put(list(paths)) |
91 | 95 | paths = [] |
| 96 | + |
92 | 97 | if paths != []: |
93 | 98 | file_path_queue.put(list(paths)) # For leftover paths < bucket_size |
94 | 99 | except FileNotFoundError: |
@@ -116,7 +121,7 @@ def walk(walk_path): |
116 | 121 | walk_thread_pool = ThreadPoolExecutor(max_workers=WORKER_THREAD_PER_PROCESS) |
117 | 122 |
|
118 | 123 | # Root directory needs to be explicitly passed |
119 | | - file_path_queue.put([path]) |
| 124 | + file_path_queue.put([(path, False)]) |
120 | 125 | dir_processed_counter.increment() |
121 | 126 |
|
122 | 127 | # Processing starts here |
@@ -149,6 +154,8 @@ def walk(walk_path): |
149 | 154 | def processor(adl, file_path_queue, finish_queue_processing_flag, method_name, acl_spec, log_queue, exception_queue): |
150 | 155 | logger = logging.getLogger(__name__) |
151 | 156 |
|
| 157 | + removed_default_acl_spec = ",".join([x for x in acl_spec.split(',') if not x.lower().startswith("default")]) |
| 158 | + |
152 | 159 | try: |
153 | 160 | logger.addHandler(logging.handlers.QueueHandler(log_queue)) |
154 | 161 | logger.propagate = False # Prevents double logging |
@@ -178,8 +185,14 @@ def func_wrapper(func, path, spec): |
178 | 185 | file_paths = file_path_queue.get(timeout=0.1) |
179 | 186 | file_path_queue.task_done() # Will not be called if empty |
180 | 187 | for file_path in file_paths: |
| 188 | + is_file = file_path[1] |
| 189 | + if is_file: |
| 190 | + spec = removed_default_acl_spec |
| 191 | + else: |
| 192 | + spec = acl_spec |
| 193 | + |
181 | 194 | logger.log(logging.DEBUG, "Starting on path:" + str(file_path)) |
182 | | - function_thread_pool.submit(func_wrapper, adl_function, file_path, acl_spec) |
| 195 | + function_thread_pool.submit(func_wrapper, adl_function, file_path[0], spec) |
183 | 196 | except Empty: |
184 | 197 | pass |
185 | 198 |
|
|
0 commit comments