open_file
open_file copied to clipboard
don't use `system` to open files
This removes the ability to use system
to open files. Instead we use Process.runSync
.
Quoting the manpage for system
:
Any user input that is employed as part of command should be carefully sanitized, to ensure that unexpected shell commands or command options are not executed.
AFAICT only spaces are replaced with \
right now. This is not enough, and invoking the
system
function is also completely unnecessary. Creating a new process directly is both
simpler and better. This option was introduced in https://github.com/crazecoder/open_file/pull/127,
however only on linux and not as the default. This is not sufficient.
Without this PR, running the following in an unsandboxed flutter app on linux would open gnome-calculator
(if installed, but you can place any command in there that will be executed):
OpenFile.open(";gnome-calculator");
I haven't tested this on macOS but it should work there similarly to linux.
I agree, also see https://github.com/crazecoder/open_file/issues/150#issuecomment-874221235 (read the man page)
and this one for solving the encoding of spaces and special chars (xdg-open supports uri's): https://github.com/crazecoder/open_file/pull/151/files/632eeeed2b38f4666effaba9a0d41ad3fe5c738e..af2e4e63ad32f2c041645c6cd73b76c59a735cf3#discussion_r663921596
Hi, nice PR but when I tried to open a music file using this then it made my application hang on linux until I close my music player.
The solution can be to run this command asynchronously
Thanks for pointing this out, it should be fixed now.
@crazecoder Any status on this PR?
@prateekmedia @miDeb Your change does not seem to be working with a simple scenario like this:
OpenFile.open('~/Downloads/flutter.png');
Tested on Linux (Ubuntu)
@javaherisaber your "simple use case" requires a shell to expand the path ~
. My change however removed the execution through the shell, therefore no shell expansion is happening and you can only open relative or absolute paths. At least that's what I think is happening.
@miDeb I don't know much about Linux terminologies, but wouldn't it be a use-case for other users that rely on shell? Can you share some of your usecases?
I would argue this package's job is to open the file that is located at the path specified, not necessarily to modify the path by performing shell expansion (e.g. expanding ~
to the user's home directory)
@miDeb is right, this package will only be used when the file path is known either relative or absolute, in both the cases we will have the correct path and not the path with ~
instead of home directory.