Fixing Windows Program Detection #241

Merged
merged 1 commit into from Apr 9, 2014

Projects

None yet

3 participants

@Sn0wCrack

command is currently not ported for windows, which however is.
To remain intact with the current code already in place, it will detect if the server is running windows or not.

@Sn0wCrack Sn0wCrack Fixing Windows Program Detection
command is currently not ported for windows, which however is.
To remain intact with the current code already in place, it will detect
if the server is running windows or not.
064527a
@CrazyMonster

which is not a POSIX standard command, which is why usually command or type are used instead. If Windows supports type, I think we can safely use it instead of two different commands depending on the platform.

The invocation to achieve the desired behavior is type -p <cmd>.

Well, type is DOS command still in cmd.exe, even if type did exist on Windows I'm not sure how that'd be handled.
Windows itself isn't POSIX compliant anyways, however to even get this to work you would need a POSIX environment (I'm currently using cygwin), we could just use the DOS command where, it gives a similar output to which but with a DOS Path, shouldn't require changing the RegEx, however, with the Windows detection in place maybe changing the .exe search in the RegEx on the Unix side to just search for tar, zip, etc. Without the .exe check.

Basically, in my search from cygwin to mingw, I couldn't find the package for type or command.

@CrazyMonster

You couldn't find them because they're implemented as shell builtins, you will find them in the bash package:

$ type type
type is a shell builtin

Regarding POSIX compliance, I think I forgot a sentence in the previous comment (I shouldn't legally be allowed to write stuff in the evening LMAO)... What I was trying to say is that we could use which on all platforms, but, because it isn't a standard command, it isn't always available, so it's better to use other commands.

@Sn0wCrack

I guess type would really depend on how h5ai is executes the command, is it just a exec() or shell_exec()? I'm unsure how using it through preg_match would work without a secondary command parsing the information.

If type comes up dry, there's always where, since it's detecting windows, as long as it's not before Windows Server 2003 the where command will work.

And as for type I'll look into the different Terminal Emulators on Windows (bash, sh, zsh) and see if any result in having type there, as when I ran type previously under cygwin it return with the Windows type command.

Also, to that extra sentence: It's detecting windows, so I'd just do the above, providing compliance for all systems is really hard, but yeah, having a default command to check is good, so that's basically why my suggestion for where came into play.

@Sn0wCrack Sn0wCrack commented on the diff Nov 28, 2013
src/_h5ai/server/php/inc/App.php
@@ -282,11 +282,19 @@ public function get_server_checks() {
}
$exif = function_exists("exif_thumbnail");
$cache = @is_writable($this->get_cache_abs_path());
- $tar = @preg_match("/tar(.exe)?$/i", `command -v tar`) > 0;
- $zip = @preg_match("/zip(.exe)?$/i", `command -v zip`) > 0;
- $convert = @preg_match("/convert(.exe)?$/i", `command -v convert`) > 0;
- $ffmpeg = @preg_match("/ffmpeg(.exe)?$/i", `command -v ffmpeg`) > 0;
- $du = @preg_match("/du(.exe)?$/i", `command -v du`) > 0;
+ if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
+ $tar = @preg_match("/tar(.exe)?$/i", `which tar`) > 0;
@Sn0wCrack
Sn0wCrack Nov 28, 2013

Which where is which where, where which is where and where is which?

@lrsjng lrsjng merged commit cbbefe1 into lrsjng:develop Apr 9, 2014
@lrsjng
Owner

@Sn0wCrack @CrazyMonster Thanks! Looks good this way (checking for WIN os).

@lrsjng lrsjng added the Translation label Apr 9, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment