pfind/pfilesearch modification

Moderator: Forum moderators

Post Reply
don570
Posts: 699
Joined: Sat Nov 21, 2020 4:43 pm
Has thanked: 5 times
Been thanked: 118 times

pfind/pfilesearch modification

Post by don570 »

pfilesearch-modification.pet
(5.26 KiB) Downloaded 80 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

________________________________________________

Last edited by don570 on Sat Aug 27, 2022 9:49 pm, edited 2 times in total.
User avatar
bigpup
Moderator
Posts: 7031
Joined: Tue Jul 14, 2020 11:19 pm
Location: Earth, South Eastern U.S.
Has thanked: 925 times
Been thanked: 1535 times

Re: pfind/pfilesearch modification

Post 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.
.

The things you do not tell us, are usually the clue to fixing the problem.
When I was a kid, I wanted to be older.
This is not what I expected :o

don570
Posts: 699
Joined: Sat Nov 21, 2020 4:43 pm
Has thanked: 5 times
Been thanked: 118 times

Re: pfind/pfilesearch modification

Post by don570 »

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

zigbert
Posts: 88
Joined: Sat Jul 18, 2020 10:44 pm
Has thanked: 22 times
Been thanked: 24 times

Re: pfind/pfilesearch modification

Post by zigbert »

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

Thank you!

don570
Posts: 699
Joined: Sat Nov 21, 2020 4:43 pm
Has thanked: 5 times
Been thanked: 118 times

woof issue

Post 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.
__________________________________________

User avatar
MochiMoppel
Posts: 1243
Joined: Mon Jun 15, 2020 6:25 am
Location: Japan
Has thanked: 21 times
Been thanked: 444 times

Re: pfind/pfilesearch modification

Post 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.

don570
Posts: 699
Joined: Sat Nov 21, 2020 4:43 pm
Has thanked: 5 times
Been thanked: 118 times

Re: pfind/pfilesearch modification

Post 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
___________________________________

williams2
Posts: 1062
Joined: Sat Jul 25, 2020 5:45 pm
Been thanked: 305 times

Re: pfind/pfilesearch modification

Post 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.

User avatar
MochiMoppel
Posts: 1243
Joined: Mon Jun 15, 2020 6:25 am
Location: Japan
Has thanked: 21 times
Been thanked: 444 times

Re: pfind/pfilesearch modification

Post 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".

don570
Posts: 699
Joined: Sat Nov 21, 2020 4:43 pm
Has thanked: 5 times
Been thanked: 118 times

github

Post by don570 »

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

Burunduk
Posts: 257
Joined: Thu Jun 16, 2022 6:16 pm
Has thanked: 7 times
Been thanked: 127 times

Re: pfind/pfilesearch modification

Post 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
Attachments
pfilesearch-2.3-maybe-fix.pet
For testing only. For Fossapup64.
(7.89 KiB) Downloaded 138 times
don570
Posts: 699
Joined: Sat Nov 21, 2020 4:43 pm
Has thanked: 5 times
Been thanked: 118 times

pfilesearch - 2.3 maybe

Post by don570 »

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

It solved my problems. :thumbup2:
___________________________________________

Post Reply

Return to “Filesystem”