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

Add check that convert is a file and not a directory #156

Closed
Maroko opened this issue Mar 31, 2021 · 5 comments
Closed

Add check that convert is a file and not a directory #156

Maroko opened this issue Mar 31, 2021 · 5 comments
Assignees
Milestone

Comments

@Maroko
Copy link

Maroko commented Mar 31, 2021

Describe the bug
I can't save the scan after scanning.

To Reproduce
Steps to reproduce the behavior:

  1. Go to the website
  2. Error: TypeError: NetworkError when attempting to fetch resource. appears
  3. Click on scan and wait for the scan to finish
  4. Error: {"message":"/usr/bin/convert './data/temp/~tmp-scan-0-0001.tif' -background '#808080' -extent '634.8425196850394x874.0157480314961-0-0' -resize 868 './data/preview/preview.tif' exited with code: 126, stderr: /bin/sh: 1: /usr/bin/convert: Permission denied\n","code":-1. Hopefully I haven't made any spelling mistakes, the error message cannot be copied.

Expected behavior
The scan is downloaded

Screenshots
First error:
2021-03-31 22_26_37-scanserv-js

Second error:
2021-03-31 22_27_04-scanserv-js

Error when running node server/server.js:
2021-03-31 23_17_12-pi@raspberrypi_ _var_www_scanservjs

Client (please complete the following information):

  • Browser: Firefox
  • Version: 87.0

Server (please complete the following information):

  • OS: Raspbian 10 (buster)
  • Node version: 15.13.0
  • NPM version: 7.7.6
  • Docker version: not running in docker

Logs
scanservjs.log.installed.txt

@sbs20 sbs20 self-assigned this Mar 31, 2021
@sbs20
Copy link
Owner

sbs20 commented Apr 1, 2021

Hi. I just did a clean install on a pi and it seems to work. Did you use the install script?

The problem you are seeing is on "preview". Specifically, scanservjs is running convert on the scanned image but getting permission denied. This seems odd to me - my guess is that the current user (running scanservjs) does not have permissions to output to the directory.

My further guess is that the owner of /var/www/scanservjs/data/preview is the scanservjs user.

[sbs20 @ pi]: ~> $ ls -al /var/www/scanservjs/data/preview/
total 3168
drwxr-xr-x 2 scanservjs users    4096 Apr  1 09:01 .

The software is meant to run as the same user scanservjs - which is what happens (or at least should happen) if you sudo systemctl start scanservjs

Whereas it looks above like you're running this as the default pi user, which won't have permission.

Just try: sudo systemctl start scanservjs and see if that works.

@Maroko
Copy link
Author

Maroko commented Apr 1, 2021

Yes, I've used the install script.

I've tried it again:

  • Uninstalled the server (uninstall.sh)
  • Uninstalled nodejs and npm
  • Run the install script line by line
  • Both errors still exist

Checked the folder permission
2021-04-01 16_32_05-pi@raspberrypi_ ~
and run sudo systemctl start scanservjs, still same errors.

scanservjs.log.installed.txt

@sbs20
Copy link
Owner

sbs20 commented Apr 1, 2021

UPDATE I thought I'd reproduced the issue, but it was a leftover test case from earlier today where I'd forcibly set the owner of preview.tif to root. Back to the plan below.

Thanks for the update. Very odd. Would you be up for trying the following? It recreates what scanimage is doing:

# Change PWD to app dir
cd /var/www/scanservjs

# Be the scanservjs user
sudo su scanservjs

# Run a scan
/usr/bin/scanimage -d 'hpaio:/usb/Photosmart_C4200_series?serial=MY78OJM0MZ04VP' --mode 'Color' --source 'Flatbed' --resolution 75 -l 0 -t 0 -x 215 -y 296 --format 'tiff' --brightness 0 --contrast 0 > ./data/temp/~tmp-scan-0-0001.tif

# See what's created
ls -al ./data/temp/

# Create the preview - it's this which is failing
/usr/bin/convert './data/temp/~tmp-scan-0-0001.tif' -background '#808080' -extent '634.8425196850394x874.0157480314961-0-0' -resize 868 './data/preview/preview.tif'

@Maroko
Copy link
Author

Maroko commented Apr 1, 2021

I found the error. The last command failed, because /usr/bin/convert is a directory. I've uninstalled scanservjs, sane and imagemagick, reinstalled it all with your installation instructions (sane and scanservjs).

ls -al /usr/bin/convert with the error:
drwxrwxrwx 2 root root 4096 Mär 31 21:51
Now:
lrwxrwxrwx 1 root root 25 Apr 1 18:55 /usr/bin/convert -> /etc/alternatives/convert

Now it works. Either the previous installation was corrupt or not suitable for scanservjs (I've used this one before I found scanservjs) or while trying to fix the error I've made a mistake. Thank you so much for your fast help! Is there a way I can buy you a coffee/beer?
And maybe this issue will save other people a lot of time who make the same mistake as me.

@Maroko Maroko closed this as completed Apr 1, 2021
@sbs20
Copy link
Owner

sbs20 commented Apr 1, 2021

Hooray!! I'm so pleased you found the problem - I even installed node 15 to see if that would recreate it! Thank you for letting me know.

I am going to reopen this issue and add a check that convert is a file rather than directory.

Thank you so much for your fast help! Is there a way I can buy you a coffee/beer?

My pleasure! I don't have a way at the moment, but it's a kind offer. Just pay it forward 😄

@sbs20 sbs20 reopened this Apr 1, 2021
@sbs20 sbs20 changed the title Can't save scan on Raspberry Pi Add check that convert is a file and not a directory Apr 1, 2021
@sbs20 sbs20 added this to the v2.8.2 milestone Apr 3, 2021
sbs20 added a commit that referenced this issue Apr 3, 2021
This was referenced Apr 3, 2021
@sbs20 sbs20 closed this as completed Apr 3, 2021
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

No branches or pull requests

2 participants