Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fixing Windows Program Detection #241

Merged
merged 1 commit into from

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
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;

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@lrsjng lrsjng merged commit cbbefe1 into lrsjng:develop
@lrsjng
Owner

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

@lrsjng lrsjng added the Translation label
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 26, 2013
  1. @Sn0wCrack

    Fixing Windows Program Detection

    Sn0wCrack authored
    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.
This page is out of date. Refresh to see the latest.
Showing with 13 additions and 5 deletions.
  1. +13 −5 src/_h5ai/server/php/inc/App.php
View
18 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;

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ $zip = @preg_match("/zip(.exe)?$/i", `which zip`) > 0;
+ $convert = @preg_match("/convert(.exe)?$/i", `which convert`) > 0;
+ $ffmpeg = @preg_match("/ffmpeg(.exe)?$/i", `which ffmpeg`) > 0;
+ $du = @preg_match("/du(.exe)?$/i", `which du`) > 0;
+ } else {
+ $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;
+ }
return array(
"idx" => $this->app_abs_href . "server/php/index.php",
Something went wrong with that request. Please try again.