MCPcopy Create free account
hub / github.com/boyter/scc / processFile

Function processFile

processor/workers.go:749–844  ·  view source on GitHub ↗

Process a single file File must have been read to job.Content already

(job *FileJob)

Source from the content-addressed store, hash-verified

747// Process a single file
748// File must have been read to job.Content already
749func processFile(job *FileJob) bool {
750 fileStartTime := makeTimestampNano()
751
752 contents := job.Content
753
754 // Needs to always run to ensure the language is set
755 job.Language = DetermineLanguage(job.Filename, job.Language, job.PossibleLanguages, job.Content)
756
757 remapped := false
758 if RemapAll != "" {
759 hardRemapLanguage(job)
760 }
761
762 // If the type is #! we should check to see if we can identify
763 if job.Language == SheBang {
764 if RemapUnknown != "" {
765 remapped = unknownRemapLanguage(job)
766 }
767
768 // if we didn't remap we then want to see if it's a #! map
769 if !remapped {
770 cutoff := 200
771
772 // To avoid runtime panic check if the content we are cutting is smaller than 200
773 if len(contents) < cutoff {
774 cutoff = len(contents)
775 }
776
777 lang, err := DetectSheBang(string(contents[:cutoff]))
778 if err != nil {
779 printWarnF("unable to determine #! language for %s", job.Location)
780 return false
781 }
782
783 printWarnF("detected #! %s for %s", lang, job.Location)
784 job.Language = lang
785 LoadLanguageFeature(lang)
786 }
787 }
788
789 CountStats(job)
790
791 if Duplicates {
792 duplicates.mux.Lock()
793 jobHash := job.Hash.Sum(nil)
794 if duplicates.Check(job.Bytes, jobHash) {
795 printWarnF("skipping duplicate file: %s", job.Location)
796 duplicates.mux.Unlock()
797 return false
798 }
799
800 duplicates.Add(job.Bytes, jobHash)
801 duplicates.mux.Unlock()
802 }
803
804 if IgnoreMinified && job.Minified {
805 printWarnF("skipping minified file: %s", job.Location)
806 return false

Callers 1

fileProcessorWorkerFunction · 0.85

Calls 11

makeTimestampNanoFunction · 0.85
DetermineLanguageFunction · 0.85
hardRemapLanguageFunction · 0.85
unknownRemapLanguageFunction · 0.85
DetectSheBangFunction · 0.85
printWarnFFunction · 0.85
LoadLanguageFeatureFunction · 0.85
CountStatsFunction · 0.85
printTraceFFunction · 0.85
CheckMethod · 0.80
AddMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…