Tiny Core Base > TCB Tips & Tricks

How to find which extension provides a file

<< < (7/14) > >>

Rich:
Hi CNK

--- Quote from: CNK on November 18, 2024, 04:36:19 PM --- ... I'd also suggest showing the help info if provides.sh is run with no arguments.
--- End quote ---
I initially did that, but then reverted back to  exit 1  because I didn't want to
risk changing a behavior that a program or script might be relying on.

Although you can now enter  usr/local/bin  without escaping the slashes, it will
still accept  usr\/local\/bin  so as not to break anything that might rely on that
behavior. The idea was to try to enhance the behavior without changing expected
behavior.

polikuo:

--- Quote from: Rich on November 18, 2024, 03:14:23 PM ---
--- Quote ---
--- Code: ---+[ $NZ -eq 1 ] || [ -n "$(find $LIST -mmin +15)" ] && UpdateProvidesDB
--- End code ---

--- End quote ---
That's pretty clever, but was the intent to override the -nz command
line switch every 15 minutes?

Maybe it makes more sense to remove the -nz command line switch
and just let it run a check when the file is at least 15 minutes old.

I would like to hear some opinions on this please.

--- End quote ---
Hi, Rich.
In a way, yes.
Perhaps wrapping the "find condition" into the UpdateProvidesDB would be better, but they are equivalent.
The "overriding" only occur when "-nz" is not passed, making the default behavior of UpdateProvidesDB only to update if the interval is greater than 15 minutes.

--- Code: ------ provides.sh
+++ /usr/local/bin/provides.sh
@@ -18,6 +18,7 @@
 # --------------------------------------------------------------- #
 UpdateProvidesDB()
 {
+[ -n "$(find $LIST -mmin +15)" ] || return 0
 getMirror
 cd "$TCEDIR"
 if zsync -i "$LIST" -q "$MIRROR"/"$DB".zsync
@@ -32,6 +33,7 @@
 fi
 chmod g+rw "$DB"
 cd - > /dev/null
+touch $LIST
 }
 # --------------------------------------------------------------- #

--- End code ---

As for the -nz switch, I incline to remove it cause extra code results in extra chance for unintentional behavior.
For instance, this would trigger the -nz switch:

--- Code: ---time provides.sh stupid-filename-nz
real    0m 0.13s
user    0m 0.11s
sys     0m 0.02s

--- End code ---

Are you planning to upload the newer version into the Github Core-scripts repo ?

Rich:
Hi polikuo

--- Quote from: polikuo on November 18, 2024, 10:10:11 PM --- ... For instance, this would trigger the -nz switch: ...
--- End quote ---
Actually, the way it's coded the -nz switch will not trigger:

--- Code: ---tc@E310:~/Scripting/Provides$ time ./provides.sh stupid-filename-nz
NZ=1    TARGET=stupid-filename
real    0m 1.74s
user    0m 0.48s
sys     0m 0.22s
tc@E310:~/Scripting/Provides$
--- End code ---
As you can see, NZ is still set to 1. However, because of the way -nz is
removed from the command, stupid-filename-nz is now 3 characters short.
I did figure out how to fix it:

--- Code: ---tc@E310:~/Scripting/Provides$ time ./provides.sh -nzstupid-filename-nz
NZ=1    TARGET=-nzstupid-filename-nz
real    0m 1.19s
user    0m 0.41s
sys     0m 0.23s
tc@E310:~/Scripting/Provides$
--- End code ---
Both a leading and trailing -nz in a filename are safe. And it can still
remove  -nz  from the command,


--- Quote --- ... As for the -nz switch, I incline to remove it cause extra code results in extra chance for unintentional behavior. ...
--- End quote ---
I'm leaning in that direction too. Adding the file age test to UpdateProvidesDB() is
looking more and more attractive.


--- Quote --- ... Are you planning to upload the newer version into the Github Core-scripts repo ?
--- End quote ---
I'd like it to be added to Core-scripts. We'll see what curaga has to say about it.
If curaga accepts it, I'll let someone who knows their way around github submit it.

I was also considering creating an extension to allow current and previous versions
of Tinycore to run an updated provides.sh.

I'd like to see if we get any more comments on this.

polikuo:
Hi, Rich.
Here's a loophole that I missed

--- Code: ------ provides.sh
+++ /usr/local/bin/provides.sh
@@ -18,6 +18,7 @@
 # --------------------------------------------------------------- #
 UpdateProvidesDB()
 {
+[ -f $LIST ] && [ -z "$(find $LIST -mmin +15)" ] && return 0
 getMirror
 cd "$TCEDIR"
 if zsync -i "$LIST" -q "$MIRROR"/"$DB".zsync
@@ -32,6 +33,7 @@
 fi
 chmod g+rw "$DB"
 cd - > /dev/null
+touch $LIST
 }
 # --------------------------------------------------------------- #

--- End code ---

If the provides.db does not exist, the checker also returns.
The logic now should be OK.

GNUser:

--- Quote from: Rich on November 19, 2024, 12:32:58 AM ---I'd like to see if we get any more comments on this.

--- End quote ---
Hi Rich. I love your improvements to provides.sh. Thank you. I always thought that script could be easier to use.

My vote is to eliminate the  -nz  switch. I'd say if  provides.db  is older than 24 hours and there is a network connection, to go ahead and automatically update provides.db. Maybe provide a switch if user wants to update  provides.db  regardless of its age?

It would be nice for no arguments to cause help to be printed, but I understand your reason for not doing that. The  -h  and  --help  are working as expected.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version