6868from scancode .api import get_licenses
6969from scancode .api import get_package_infos
7070from scancode .api import get_urls
71+ from scancode .api import Resource
7172
7273from scancode .cache import get_scans_cache_class
7374from scancode .cache import ScanFileCache
8081from scancode .utils import BaseCommand
8182from scancode .utils import compute_fn_max_len
8283from scancode .utils import fixed_width_file_name
83- from scancode .utils import get_relative_path
8484from scancode .utils import progressmanager
8585
8686
@@ -578,7 +578,7 @@ def scan(input_path,
578578
579579 pool = None
580580
581- resources = resource_paths (input_path , pre_scan_plugins = pre_scan_plugins )
581+ resources = resource_paths (input_path , diag , scans_cache_class , pre_scan_plugins = pre_scan_plugins )
582582 paths_with_error = []
583583 files_count = 0
584584
@@ -731,26 +731,19 @@ def _resource_logger(logfile_fd, resources):
731731 yield back the resources.
732732 """
733733 file_logger = ScanFileCache .log_file_path
734- for posix_path , rel_path in resources :
735- file_logger (logfile_fd , rel_path )
736- yield posix_path , rel_path
734+ for resource in resources :
735+ file_logger (logfile_fd , resource . rel_path )
736+ yield resource
737737
738738
739- def _scanit (paths , scanners , scans_cache_class , diag , timeout = DEFAULT_TIMEOUT , processes = 1 ):
739+ def _scanit (resource , scanners , scans_cache_class , diag , timeout = DEFAULT_TIMEOUT , processes = 1 ):
740740 """
741741 Run scans and cache results on disk. Return a tuple of (success, scanned relative
742742 path) where sucess is True on success, False on error. Note that this is really
743743 only a wrapper function used as an execution unit for parallel processing.
744744 """
745- abs_path , rel_path = paths
746- # always fetch infos and cache.
747- infos = OrderedDict ()
748- infos ['path' ] = rel_path
749- infos .update (scan_infos (abs_path , diag = diag ))
750-
751745 success = True
752746 scans_cache = scans_cache_class ()
753- is_cached = scans_cache .put_info (rel_path , infos )
754747
755748 # note: "flag and function" expressions return the function if flag is True
756749 # note: the order of the scans matters to show things in logical order
@@ -766,23 +759,23 @@ def _scanit(paths, scanners, scans_cache_class, diag, timeout=DEFAULT_TIMEOUT, p
766759 if any (scanner_functions ):
767760 # Skip other scans if already cached
768761 # FIXME: ENSURE we only do this for files not directories
769- if not is_cached :
762+ if not resource . is_cached :
770763 # run the scan as an interruptiple task
771- scans_runner = partial (scan_one , abs_path , scanners , diag )
764+ scans_runner = partial (scan_one , resource . abs_path , scanners , diag )
772765 success , scan_result = interrupter (scans_runner , timeout = timeout )
773766 if not success :
774767 # Use scan errors as the scan result for that file on failure this is
775768 # a top-level error not attachedd to a specific scanner, hence the
776769 # "scan" key is used for these errors
777770 scan_result = {'scan_errors' : [scan_result ]}
778771
779- scans_cache .put_scan (rel_path , infos , scan_result )
772+ scans_cache .put_scan (resource . rel_path , resource . get_info () , scan_result )
780773
781774 # do not report success if some other errors happened
782775 if scan_result .get ('scan_errors' ):
783776 success = False
784777
785- return success , rel_path
778+ return success , resource . rel_path
786779
787780
788781def build_ignorer (ignores , unignores ):
@@ -801,10 +794,10 @@ def build_ignorer(ignores, unignores):
801794 return partial (ignore .is_ignored , ignores = ignores , unignores = unignores )
802795
803796
804- def resource_paths (base_path , pre_scan_plugins = ()):
797+ def resource_paths (base_path , diag , scans_cache_class , pre_scan_plugins = ()):
805798 """
806- Yield tuples of (absolute path, base_path-relative path) for all the files found
807- at base_path (either a directory or file) given an absolute base_path. Only yield
799+ Yield `Resource` objects for all the files found at base_path
800+ (either a directory or file) given an absolute base_path. Only yield
808801 Files, not directories.
809802 absolute path is a native OS path.
810803 base_path-relative path is a POSIX path.
@@ -831,11 +824,10 @@ def resource_paths(base_path, pre_scan_plugins=()):
831824 resources = fileutils .resource_iter (base_path , ignored = ignorer )
832825
833826 for abs_path in resources :
834- posix_path = fileutils .as_posixpath (abs_path )
835- # fix paths: keep the path as relative to the original
836- # base_path. This is always Unicode
837- rel_path = get_relative_path (posix_path , len_base_path , base_is_dir )
838- yield abs_path , rel_path
827+ resource = Resource (scans_cache_class , abs_path , base_is_dir , len_base_path )
828+ # always fetch infos and cache.
829+ resource .put_info (scan_infos (abs_path , diag = diag ))
830+ yield resource
839831
840832
841833def scan_infos (input_file , diag = False ):
0 commit comments