ndwarshuis / org-sql

SQL backend for Emacs Org-Mode
GNU General Public License v3.0
100 stars 9 forks source link

Hard-coded path to sqlite3 - No such a file or directory, /usr/bin/sqlite3 #8

Closed jarofromel closed 4 years ago

jarofromel commented 4 years ago

Emacs 27.1, Org-mode 9.4, Org-sql 1.02 I run into this error when I tried to use org-sql in Termux (Android Terminal emulator). It doesn't have the standard file hierarchy due to limitations in Android.

The error origin seems to be here (defconst org-sql--sqlite-exe "/usr/bin/sqlite3")

A slightly better solution would be to check the existence of executable in the PATH. I see you are aware of this, you have TODO mentioning Windows there.

PS: I quite enjoy using your package for last several months, thanks. PS: I may pull something to solve it, it sounds like a good starter issue for someone who doesn't have experience with Elisp (me).

ndwarshuis commented 4 years ago

Feel free to open a PR for this ;) I haven't had the bandwidth to focus much on this in the past month or so. This actually might be super easy to solve just by taking the "/usr/bin/" part off the string since those eventually go to call-process which accepts executable names and performs the lookup in PATH (which at some point I apparently forgot).

Also, what is your setup? I'm not familiar at all with running emacs on Android. If it isn't super convoluted it would be good to add the environment you are using to the testing suite.

jarofromel commented 4 years ago

Well, just taking the "/usr/bin/" is not enough (my wild guess is somewhere in this part, the path is expected). This works: (defconst org-sql--sqlite-exe (executable-find "sqlite3"))

However, somewhat similar error shows after that:

f--write-bytes: Opening output file: No such file or directory, /tmp/org-sql-cmd-1605289747

Again, the hard-coded path is the origin. In this case I am not sure if there is some generic definition of a temporary directory (it is %TMP% in Windows, but on *nix? )?

Regarding the setup where I found the error, Termux is an app from Playstore/F-droid. After the install you have at your disposal the command line environment (package manager based on apt, common packages etc.). I just installed emacs (it is one of the many available packages), synced my (doom-)emacs config (over syncthing) to Android and symlinked it to the Termux file hierarchy - all of this over the SSH (you can run sshd in Termux, so your phone is another device you can control from your main computer). I had low expectation before, but the it works almost flawlessly. In spite of all the above, I think it comes the category "convoluted". I use it infrequently, just to check my org-mode notes when I don't have an laptop around.

ndwarshuis commented 4 years ago

Well, just taking the "/usr/bin/" is not enough (my wild guess is somewhere in this part, the path is expected). This works: (defconst org-sql--sqlite-exe (executable-find "sqlite3"))

Interesting. So in your case call-process must be searching in the wrong PATH or an incomplete PATH. The reason why I thought the simple string change would work is because (org-sql--run-command "md5sum" "/bin/emacs") will return the MD5 of the emacs binary when I run it on my desktop (md5sum is used elsewhere in the code), so it knows the "md5sum" is a valid command and is able to find it. Because of this, what you have with executable-find is likely the best solution, but it will also be required for md5sum, pgsql, createdb, and dropdb (although the last three would only throw an error if you were trying to sync to a postgres database).

However, somewhat similar error shows after that

f--write-bytes: Opening output file: No such file or directory, /tmp/org-sql-cmd-1605289747

This is a bit surprising, since I would think the temp directory would also be the same on android as linux (which is just "/tmp"). What is the value of temporary-file-directory (this is an emacs variable)? I also realized looking at this again that my code actually duplicates some emacs built-in functions (eg make-temp-file), so long term it should be rewritten in terms of those.

In spite of all the above, I think it comes the category "convoluted". I use it infrequently, just to check my org-mode notes when I don't have an laptop around.

It might seem "convoluted" but I'm sure others would appreciate more ways to use emacs on mobile, particularly with org-mode. Setting up the testing environment is probably be an entirely separate issue which would require a docker image with the termux environment and emacs/org-sql installed on top of it, and then all that put in the github action workflow (I'm not yet sure exactly how to do that, although there is a termux docker image).

The things you noted above would likely allow it to work without the testing environment though, but adding the environment would allow the README to say "supported on Termux/Android" ;)

jarofromel commented 4 years ago

Well, just taking the "/usr/bin/" is not enough (my wild guess is somewhere in this part, the path is expected). This works: (defconst org-sql--sqlite-exe (executable-find "sqlite3"))

Interesting. So in your case call-process must be searching in the wrong PATH or an incomplete PATH......

I was wrong and you right, taking the "/usr/bin" is enough (I probably didn't reload emacs config when I evaluated that).

However, somewhat similar error shows after that f--write-bytes: Opening output file: No such file or directory, /tmp/org-sql-cmd-1605289747

This is a bit surprising, since I would think the temp directory would also be the same on android as linux (which is just "/tmp"). What is the value of temporary-file-directory (this is an emacs variable)?

I see, this can solve it. The value of temporary-file-directory is "$PREFIX/usr/tmp" where $PREFIX is '/data/data/com.termux/files' - this is the place where termux emulates the file hierarchy (because the real file hierarchy on which is Android build is blocked to access by apps - https://wiki.termux.com/wiki/Differences_from_Linux)

In spite of all the above, I think it comes the category "convoluted". I use it infrequently, just to check my org-mode notes when I don't have an laptop around.

It might seem "convoluted" but I'm sure others would appreciate more ways to use emacs on mobile, particularly with org-mode....

Sounds fair, I'll keep it in my mind, because there are serious issues with Termux and new Android versions (10, 11) which limits usability of Termux on Android - so work on setting the test environment could be useless (https://github.com/termux/termux-packages/wiki/Termux-and-Android-10 and https://github.com/termux/termux-app/issues/1072)

I'll send PR dealing with 1) and 2) in the mean time.