Skip to content

Conversation

@nblock
Copy link
Contributor

@nblock nblock commented Oct 15, 2022

Exit make_thumbs early when invoked with an empty first argument "" to avoid a syntax error.

@jarun
Copy link
Owner

jarun commented Oct 17, 2022

@luukvbaal @N-R-K can you please review?

@0xACE
Copy link
Collaborator

0xACE commented Oct 17, 2022

What syntax error are you referring to?

Seems like the previous authors specifically call the function with with a empty string, your [ -z "$1" ] && return would short-circuit the intended code...

@nblock
Copy link
Contributor Author

nblock commented Oct 18, 2022

The syntax errors displayed on invocation of imgview with imv installed are:

line 34: [: : integer expression expected
line 49: [: : integer expression expected

@0xACE you are right, this short-ciruits the code. Another possible fix is to call make_thumbs with an integer argument not handled inside the function instead of an empty string, such as make_thumbs 9.

plugins/imgview Outdated
make_thumbs() {
[ -z "$1" ] && return
mkdir -p "$NNN_PREVIEWDIR$dir" || return
if [ "$1" -eq 3 ]; then
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haven't looked too carefully, but does this work?

Suggested change
if [ "$1" -eq 3 ]; then
if [ -n "$1" ] && [ "$1" -eq 3 ]; then

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, as long as all other occurrences in the function are guarded, too. How about evaluating the argument as a string and using = or != for comparison?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I must confess I don't quite remember my thinking when I rewrote this plugin when merging the image plugins. IIRC some of the image programs require thumbnails while others already generate those themselves for certain file types. Looking at this now the arguments passed to make_thumbs() indeed don't seem to make much sense. We are passing 0, 1 3 and "", seems to me we should pass something like 0, 1, 2 and maybe -1 instead of ""? I'm not quite sure how I never ran into that syntax error, I remember thoroughly testing all the options back then.

Copy link
Contributor Author

@nblock nblock Oct 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@luukvbaal thx for your suggestion - -1 makes the intend clear. I'll update the PR shortly. I only came across this because I switched to another image viewer and purged a few others from my system.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think spelling out the option makes more sense than using magic numbers. It's shell after all :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I decided to just handle arguments as strings and keep the behavior as is.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason not to follow @N-R-K's suggestion? Should not change the behavior either right? Could you check that the commit I pushed works as expected?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you check that the commit I pushed works as expected?

Untested, but the change looks good to me.

@jarun
Copy link
Owner

jarun commented Oct 18, 2022

@luukvbaal please approve and merge when ready.

Avoids the following synax errors:
line 34: [: : integer expression expected
line 49: [: : integer expression expected
@nblock nblock force-pushed the imgview-no-thumbs branch from f82fefc to a4af478 Compare October 20, 2022 10:03
@nblock nblock changed the title imgview: skip thumbnail creation if not required imgview: handle arguments as strings Oct 20, 2022
@luukvbaal luukvbaal merged commit b511506 into jarun:master Oct 21, 2022
@luukvbaal
Copy link
Collaborator

Tested it myself, seems OK. Thanks for bringing up the issue @nblock.

@nblock nblock deleted the imgview-no-thumbs branch October 22, 2022 07:58
@jarun jarun mentioned this pull request Oct 22, 2022
1 task
@github-actions github-actions bot locked and limited conversation to collaborators Nov 22, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants