Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix validate_for_chd and unquoted log line #789

Merged
merged 2 commits into from
May 21, 2024

Conversation

reyemxela
Copy link

compression.sh line 37:

if [[ $(validate_for_chd "$1") == "true" ]] && ...

is currently broken. validate_for_chd has several log calls, and the log function echoes to stdout as well as logging to file, which causes things like this to have problems. Running find_compatible_compression_format with set -x shows what's happening:

...
++ IFS=
++ read -r line
++ echo true
+ [[ [2024-05-14 13:24:42.662] [INFO] Validating file: /home/alexmeyer/retrodeck/roms/psx/Disney-Pixar Toy Story 2 - Buzz Lightyear to the Rescue! (USA) (Rev 1).cue
[2024-05-14 13:24:42.667] [INFO] .cue/.iso/.gdi file detected
[2024-05-14 13:24:42.674] [INFO] Validating .cue associated .bin files
[2024-05-14 13:24:42.678] [INFO] Associated bin files read:
[2024-05-14 13:24:42.681] [INFO] Disney-Pixar
[2024-05-14 13:24:42.681] [WARN] Log file not found in "Toy", creating it
[2024-05-14 13:24:42.693] [INFO] Looking for /var/home/alexmeyer/retrodeck/roms/psx/Disney-Pixar Toy Story 2 - Buzz Lightyear to the Rescue! (USA) (Rev 1).bin
[2024-05-14 13:24:42.695] [INFO] .bin file found at /var/home/alexmeyer/retrodeck/roms/psx/Disney-Pixar Toy Story 2 - Buzz Lightyear to the Rescue! (USA) (Rev 1).bin
true == \t\r\u\e ]]
...

That whole log section is the string that's being compared to 'true', which obviously fails. The easy fix is what I added, which is just comparing to *true so the rest of that string doesn't affect it, but this definitely needs some re-working on a deeper level.

The other thing I fixed is one unquoted log on line 69 that breaks if the target filename has spaces in it.

@reyemxela reyemxela changed the title Fix validate_for_chd and unqouted log line Fix validate_for_chd and unquoted log line May 14, 2024
@XargonWan
Copy link
Owner

I never thought about *true, that is pretty smart.

Basically "[DEBUG] Logging this linetrue" will be evaluated as *true.

How much testing you did on this?
Is it "solid enough" for the moment?

@reyemxela
Copy link
Author

I didn't do a ton of debugging, but as a temporary fix, this should be solid enough. The validate_for_chd function prints true/false as the very last output, so there shouldn't really be any false positives/negatives.

As it is right now, chd compression just plain doesn't work because that comparison statement will never match.

But honestly, no, this isn't the BEST fix. Trying to capture output from any other function that itself that uses the log function will have the same problem, the log messages all get eaten up and captured along with the "expected" output from the function in question. We'd need a different setup to keep log output separate from "return" values of functions.

So yeah, I think this works for now, for this instance. If it would be of help, I could try digging in to the scripts and see if I can see a more solid way to do logging within value-returning functions. For something like this function where it only needs a true/false, it could actually just do a return 0 or return 1, and then the if is just checking the return code instead of capturing the output and comparing it.

@XargonWan
Copy link
Owner

That is why some functions are not logged yet. I missed this one apparently, good catch.

We might include this as an hotfix, however I personally never found a solution to the logging yet.
If you can find one for sure we will evaluate that.

Thanks a lot!

@reyemxela
Copy link
Author

I just realized a pretty simple solution to this, just make log output to stderr for its output. This allows it to still write to the console perfectly fine, while keeping log messages out of function outputs. I just did some testing and it seems to work fine.

@icenine451 icenine451 changed the base branch from main to cooker-0.8.2b May 21, 2024 15:25
@icenine451 icenine451 merged commit bbe3b01 into XargonWan:cooker-0.8.2b May 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants