Page 1 of 1

pfind/pfilesearch modification

Posted: Sat Aug 27, 2022 8:26 pm
by don570
pfilesearch-modification.pet
(5.26 KiB) Downloaded 51 times

pfind/pfilesearch modification

I discovered that pfind doesn't do a proper search in a folder that has a
dollar sign ($) in the foldername.
I tracked down that it is Zigbert's program pfilesearch that sets up the paths and variables.

I made a change in pfilesearch so that search paths that have a dollar sign now use hard quotes rather than customary soft quotes.
and that solves the problem. It's only a few extra code lines. It should work on all recent puppies.
Available download:
pfilesearch-modification.pet

Type:Compressed Archive
Size:5 KB

________________________________________________


Re: pfind/pfilesearch modification

Posted: Sat Aug 27, 2022 9:25 pm
by bigpup

something is wrong with how you attached the pet.

I am not seeing anything to click on to download it.

Oh, I see, the link is in the top right of the image. :oops:

The pet is small enough you can just attach it to the first post.
.


Re: pfind/pfilesearch modification

Posted: Sat Aug 27, 2022 9:47 pm
by don570

Thanks ...
Some strange feature of google I guess????
I made change to post.
___________________________________


Re: pfind/pfilesearch modification

Posted: Mon Aug 29, 2022 5:23 pm
by zigbert

Can you please make a pull request at github to improve pFilesearch?
... or post a diff here...

Thank you!


woof issue

Posted: Tue Aug 30, 2022 11:35 pm
by don570

Zigbert

I described the issue in github..
https://github.com/puppylinux-woof-CE/w ... ssues/3357

Also if you have the time there is an issue with soft quotes (")
in a foldername as well. Fortunately this is rare.
__________________________________________


Re: pfind/pfilesearch modification

Posted: Wed Aug 31, 2022 9:13 am
by MochiMoppel
don570 wrote: Sat Aug 27, 2022 8:26 pm

I made a change in pfilesearch so that search paths that have a dollar sign now use hard quotes rather than customary soft quotes.
and that solves the problem.

No, it does not.
I tried your patch with pFind6.3 and found that it creates more problems than it solves.
Firstly it has no effect when assigning a search directory via command line, e.g. pfind -d /path/to/test$folder
It also generated lots of broken pipe errors (couldn't find /tmp/pfind-splash) and results did not appear in pFind pane. The original version would simply return no results as it would treat it as a bash expression and consequently would convert the search directory name. Though passing such a search directory might be problematic, pFind has no problems to find files/folders with dollar signs.

pFind is very complex and I fear it would require quite a lot of work to fix it. Better fix the file name. Dollar signs in a file/folder name are a bad idea. Pfind may not be the only program to choke on them.


Re: pfind/pfilesearch modification

Posted: Wed Aug 31, 2022 11:40 pm
by don570

I am currently using fatdog 812 and Easy OS 434

They both use pfilesearch 2.2

Are you sure you modified the pfilesearch func file rather than the pfind func file??

Because simple mod like this shouldn't be causing piping errors.
It's just an if statement...
__________________________________________________

Also I added another issue to github...

https://github.com/puppylinux-woof-CE/w ... ssues/3360
___________________________________


Re: pfind/pfilesearch modification

Posted: Thu Sep 01, 2022 1:25 am
by williams2

If a double-quote is placed inside single quotes, and assigned to a shell variable,
every time that the expression is evaluated, the outer pair of quotes is removed. leaving just the contents of the outer quotes pair.

So ''"'' becomes '"'
and '"' becomes " (a single double-quote character, which causes the error message)

I prefer escaping characters like this:

\$
\\\$
\"
\\\"

which also removes a layer of escape characters, each time the expression is expanded.

There are other ways to handle shell special characters.
One way is to execute code not in a shell but execute awk or sed or other executable reading a text file that is a set of awk or sed etc commands.

For example, I have a file named escape.sed that I call from a script that list file names that I am searching for.

Code: Select all

s_ _\\ _g
s_\\__
s_\\__
s_(_\\(_g
s_)_\\)_g
s_{_\\{_g
s_}_\\}_g
s_'_\\'_g
s_\&_\\\&_g
s_\$_\\\$_g
s_;_\\;_g
s_!_\\!_g

which lists the file names with spaces, dollar signs, ampersands, etc escaped.
It is called like this sed -f /root/escape.sed (the file names are piped to the sed command)

There are probably better ways to do this, but writing this was quicker than searching for a better way.


Re: pfind/pfilesearch modification

Posted: Thu Sep 01, 2022 2:25 am
by MochiMoppel
don570 wrote: Wed Aug 31, 2022 11:40 pm

Are you sure you modified the pfilesearch func file rather than the pfind func file??

You are right, overwrote the wrong func :oops:

I think your change fixes a problem that shouldn't exist in the first place. Why not simply change line 85 from

Code: Select all

echo -n "find $FOLLOW_SYM \"$SEARCHPATH\" $EXCLUDE1 $FINDOPTIONS $NAME \"$SEARCHSTRING2\" " > $WORKDIR/pfilesearch-execfind #default find

to

Code: Select all

echo -n "find $FOLLOW_SYM '$SEARCHPATH' $EXCLUDE1 $FINDOPTIONS $NAME '$SEARCHSTRING2' " > $WORKDIR/pfilesearch-execfind #default find

to ensure that values in pfilesearch-execfind are always surrounded by single quotes, not double quotes? Seems to work.

This also eliminates a more realistic problem: Even your fix doesn't allow to search for funny files with dollar signs when the search starts in a "normal" folder like /usr. If you put a single '$' character into the search field it will act like a wildcard and finds all files. By enclosing not only the SEARCHPATH but also the SEARCHSTRING2 with single quotes it will restrict the search to "dollar files".


github

Posted: Thu Sep 01, 2022 9:16 pm
by don570

Zigbert would like github to be used.
https://github.com/puppylinux-woof-CE/w ... filesearch
____________________________________


Re: pfind/pfilesearch modification

Posted: Fri Sep 02, 2022 1:49 am
by Burunduk

Single quotes are better but they can be in a file name too. MochiMoppel is right, pfind is a complex script and it hasn't been written with weird directory names in mind. It seems easier to rewrite it from scratch than hunt for possible corner cases.

This is an attempt to fix at least the pfilesearch program. pfind also works but partially. pfind -d gives a gtkdialog error because it cannot display a "curdir" tooltip (line 212)
Tested with directory names containing $,",' and `.

Only tested briefly on Fossapup64, pfilesearch version 2.3

diff for /usr/local/pfilesearch/func

Code: Select all

18a19,20
> 	# escape some special characters - [$"`] or [$"`\]
> 	SEARCHPATHS="$(echo "$SEARCHPATHS" | sed 's/[$"`]/\\&/g')"
81c83
< 	while read SEARCHPATH; do
---
> 	while read -r SEARCHPATH; do

diff for /usr/local/pfilesearch/pfilesearch

Code: Select all

403c403,404
< for STATEMENTS in  $(gtkdialog -p pfilesearch_gui); do
---
> # escape some special chars before eval - [$"`] or [$"`\]
> for STATEMENTS in  $(gtkdialog -p pfilesearch_gui | sed 's/[$"`]/\\&/g;s/=\\/=/;s/\\"$/"/'); do

pfilesearch - 2.3 maybe

Posted: Tue Sep 06, 2022 10:12 pm
by don570

pfilesearch- 2.3 maybe
worked well when I installed it in fatdog linux and easy linux.

It solved my problems. :thumbup2:
___________________________________________