# HG changeset patch # User Claus Gittinger # Date 1326321249 -3600 # Node ID 0319362db871eac9d6b32ff7d4c4cf5834e7febb # Parent c9585b9d2697dffb096fddc0e28574bef0f784be refactored diff -r c9585b9d2697 -r 0319362db871 FindFileApplication.st --- a/FindFileApplication.st Wed Jan 11 22:55:40 2012 +0100 +++ b/FindFileApplication.st Wed Jan 11 23:34:09 2012 +0100 @@ -128,9 +128,11 @@ 'Search for files with same contents as the other file' #fileSize -'Search for files with a specific size constraint' +'Search for files with a specific size constraint ("~" means: +/- 10%)' ) + + "Modified: / 11-01-2012 / 23:32:42 / cg" ! ! !FindFileApplication class methodsFor:'history'! @@ -1236,13 +1238,12 @@ setOfFilesToSearchFor remember cache fn dirSearchedRelative| contentsString := contentsStringArg. - contentsString notNil ifTrue:[ - ignCaseInContents ifTrue:[ contentsString := contentsString asLowercase ]. + (contentsString notNil and:[ ignCaseInContents ]) ifTrue:[ + contentsString := contentsString asLowercase ]. notContentsString := notContentsStringArg. - - notContentsString notNil ifTrue:[ - ignCaseInNotContents ifTrue:[ notContentsString := notContentsString asLowercase ]. + (notContentsString notNil and:[ ignCaseInNotContents ]) ifTrue:[ + notContentsString := notContentsString asLowercase ]. filenameToCompareContentsOrNil notNil ifTrue:[ fileSizesToSearchFor := OrderedCollection new. @@ -1374,8 +1375,7 @@ (contentsString isNil and:[notContentsString isNil]) ifTrue:[ doesFileMatch := [:f | true]. ] ifFalse:[ - (self canUseGrep - and:[self useGrep value]) ifTrue:[ + (self canUseGrep and:[self useGrep value]) ifTrue:[ (ignCaseInContents not and:[ignCaseInNotContents not]) ifTrue:[ contentsString notNil ifTrue:[ notContentsString notNil ifTrue:[ @@ -1465,20 +1465,7 @@ ]. ]. ]. - self enableFileSizeFilter value ifTrue:[ - |fileSizeToCompare sizeMatch op oldDoesFileMatch| - - fileSizeToCompare := self fileSizeHolder value. - op := self fileSizeOperatorHolder value withoutSeparators. - op = '~' ifTrue:[ - sizeMatch := [:f | |sz| sz := f fileSize. sz notNil and:[sz between:fileSizeToCompare*0.9 and:fileSizeToCompare*1.1]]. - ] ifFalse:[ - op := op asSymbol. - sizeMatch := [:f | |sz| sz := f fileSize. sz notNil and:[sz perform:op with:fileSizeToCompare]]. - ]. - oldDoesFileMatch := doesFileMatch. - doesFileMatch := [:f | (sizeMatch value:f) and:[ oldDoesFileMatch value:f ]] - ]. + doesFileMatch := self fileSizeWrapperFor:doesFileMatch. ]. namePatterns isNil ifTrue:[ @@ -1650,6 +1637,34 @@ ] "Modified: / 03-08-2011 / 18:36:24 / cg" +! + +fileSizeWrapperFor:aFileMatchBlock + "possibly wrap the search-match block into a file-size matcher" + + |fileSizeToCompare sizeMatch op compare| + + self enableFileSizeFilter value ifFalse:[ ^ aFileMatchBlock ]. + + fileSizeToCompare := self fileSizeHolder value. + op := self fileSizeOperatorHolder value withoutSeparators. + op = '~' ifTrue:[ + compare := [:sz | sz between:(fileSizeToCompare*0.9) and:(fileSizeToCompare*1.1) ]. + ] ifFalse:[ + op := op asSymbol. + compare := [:sz | sz perform:op with:fileSizeToCompare ]. + ]. + + sizeMatch := [:f | + |sz| + + sz := f fileSize. + sz notNil and:[ compare value:sz ] + ]. + + ^ [:f | (sizeMatch value:f) and:[ aFileMatchBlock value:f ]] + + "Created: / 11-01-2012 / 23:17:02 / cg" ! ! !FindFileApplication methodsFor:'queries'! @@ -1703,9 +1718,9 @@ !FindFileApplication class methodsFor:'documentation'! version - ^ '$Header: /cvs/stx/stx/libtool/FindFileApplication.st,v 1.94 2012-01-11 21:55:40 cg Exp $' + ^ '$Header: /cvs/stx/stx/libtool/FindFileApplication.st,v 1.95 2012-01-11 22:34:09 cg Exp $' ! version_CVS - ^ '$Header: /cvs/stx/stx/libtool/FindFileApplication.st,v 1.94 2012-01-11 21:55:40 cg Exp $' + ^ '$Header: /cvs/stx/stx/libtool/FindFileApplication.st,v 1.95 2012-01-11 22:34:09 cg Exp $' ! !