NicolasBernaerts / ubuntu-scripts

Various installation & administration scripts for Ubuntu workstation
186 stars 94 forks source link

pdf-repair: Output file name format #58

Closed john98nf closed 2 years ago

john98nf commented 2 years ago

Hello Nicolas and dear contributors,

I came accross your repo by reading this article. It came in handy as I repaired my documents and made them readable with open-source document viewers πŸ‘. Thank you very much πŸ˜„!

I managed to locate a small typo/bug inside the pdf-repair script. In line 82, the filename variable is declared as:

ORIGINAL_FILE=$(basename "${ORIGINAL_URI}")

but in line 95 the new file is created with the command:

gio copy "${TMP_REPAIRED}" "${ORIGINAL_DIR}/${ORIGINAL_NAME}-repaired.pdf" // NAME instead of FILE

This results to the name format "-repaired.pdf" for the output. One can easily fix the typo of the variable, but still this would result to files with the pdf extension inside their name (e.g. input.pdf-repaired.pdf).

πŸ“ Proposed solution:

I would recommend a dirty fix in line 82, where we could drop the file extension from the OUTPUT_FILE variable.

ORIGINAL_FILE=$(basename "${ORIGINAL_URI}" | cut -f 1 -d '.')

⚠ This fix will not work properly if the input file has dots inside to name (e.g. input.foo.pdf).

Please, let me know if you want me to contribute to this project with this minor change.

NicolasBernaerts commented 2 years ago

I John, Thanks for the feedback. Please do not hesitate to propose a merge request with your bug correction.

john98nf commented 2 years ago

Pull request #59 has been created.

I ended up using ORIGINAL_NAME="${ORIGINAL_FILE%.*}", which is already present in other tools in the same repo and works for all file names.

I mark now this issue as closed.