ElkArte Community

Elk Development => Bug Reports => Exterminated Bugs => Topic started by: scripple on March 09, 2014, 12:46:54 pm

Title: Errors when installing and removing a package
Post by: scripple on March 09, 2014, 12:46:54 pm
I get lots of errors in the log when I install and uninstall a package I'm working on.  Since it's my first package hopefully it's my problem.  Can someone point me to a package that sets hooks, installs files and does a code edit that is known good?

Then I can see if it's my package (and how to fix it) or the install system.

Example Uninstall Errors:
Type of error: Undefined
8: Undefined variable: integration_call
index.php?action=admin;area=packages;sa=uninstall2;package=mypackage.tgz;pid=20
File: elkarte/sources/Subs.php
Line: 3931
      
Type of error: Undefined
8: Undefined variable: integration_call
elkarte/index.php?action=admin;area=packages;sa=uninstall2;package=mypackage.tgz;pid=20
File: elkarte/sources/Subs.php
Line: 3923
      
Type of error: Undefined
index.php?action=admin;area=packages;sa=uninstall2;package=mypackage.tgz;pid=20
File: elkarte/sources/Subs.php
Line: 3912

And these errors on install and uninstall

Type of error: General
2: is_dir() expects parameter 1 to be a valid path, string given
elkarte/index.php?action=admin;area=packages;sa=uninstall2;package=mypackage.tgz;pid=20
File: elkarte/sources/subs/Package.subs.php
Line: 1792
      
Type of error: General
2: file_exists() expects parameter 1 to be a valid path, string given
/elkarte/index.php?action=admin;area=packages;sa=uninstall2;package=mypackage.tgz;pid=20
File: elkarte/sources/subs/Package.subs.php
Line: 216
Title: Re: Errors when installing and removing a package
Post by: Spuds on March 09, 2014, 03:48:06 pm
There was a bug that was fixed just recently here https://github.com/Spuds/Elkarte/commit/18254a539d11f3ea7d9dd3a5f8032e8e761217c4  That affected uninstall though.

You can see some of my addons here: https://bitbucket.org/spuds_  look at the more recent ones, although they are all work in progress so they may or may not work

Title: Re: Errors when installing and removing a package
Post by: scripple on March 12, 2014, 02:03:53 am
I grabbed your hideusernames package just a few minutes ago (it was updated today) and installed it.  No errors on install but errors on uninstall.  One is what your github link fixes.  Here's the other.

Type of error: Undefined
8: Undefined variable: integration_call
.../index.php?action=admin;area=packages;sa=uninstall2;package=spuds_-elk_hideusernames-3bbba4f9bd00.zip;pid=39
File: /var/www/elkarte/sources/Subs.php
Line: 3923
Title: Re: Errors when installing and removing a package
Post by: scripple on March 12, 2014, 03:12:23 am
Ok, I found the difference between my package and yours in terms of install errors.  I am using gzipped tar files (.tgz extension) and you are using zip files.  I zipped mine instead and it installed without all the errors.

Not sure why gzipped tar files throw so many errors.
Title: Re: Errors when installing and removing a package
Post by: Spuds on March 12, 2014, 11:04:56 am
Not sure either, something else for me to check  :D
Title: Re: Errors when installing and removing a package
Post by: Spuds on March 12, 2014, 12:06:18 pm
I can see why you could get Undefined variable: integration_call and made a simple fix for now ( https://github.com/Spuds/Elkarte/commit/c3933023e8bba9d02638ed1ff61233923d45d13a ).  I tried some tar.gz files as well but did not get any errors.  If you would attach an example tar.gz package that is creating errors then I can check in to this a bit more.
Title: Re: Errors when installing and removing a package
Post by: scripple on March 12, 2014, 10:23:06 pm
Here is your hideusernames package unzipped and then tar gzipped (hope you don't mind it as the example).  When I install it using the package manager in .tgz format I get four errors.  Two each of

Type of error: General
2: is_dir() expects parameter 1 to be a valid path, string given
.../elkarte/index.php?action=admin;area=packages;sa=install2;package=spuds_-elk_hideusernames-3bbba4f9bd00.tgz;pid=0
File: .../elkarte/sources/subs/Package.subs.php
Line: 1792

Type of error: General
2: file_exists() expects parameter 1 to be a valid path, string given
.../elkarte/index.php?action=admin;area=packages;sa=install2;package=spuds_-elk_hideusernames-3bbba4f9bd00.tgz;pid=0
.../elkarte/sources/subs/Package.subs.php
Line: 216

Note:  Renamed to tar.gz as the forum wouldn't let me attach a file in .tgz format.  I've not tried installing it as tar.gz.
Title: Re: Errors when installing and removing a package
Post by: Spuds on March 13, 2014, 10:05:53 am
renamed it back to tgz and it installed w/o errors on my system. 

Since is_dir is throwing an E_WARNING i would think its a permissions issue, but I'm not sure why you are only seeing that with a tgz but not a zip?  Are you having to use FTP to install the file or does the system think it has permissions? 
Title: Re: Errors when installing and removing a package
Post by: scripple on March 13, 2014, 11:04:36 am
The system thinks it has permissions.
Title: Re: Errors when installing and removing a package
Post by: Spuds on March 13, 2014, 11:11:54 am
Than ATM, I'm stumped !  Maybe someone else has some ideas on this one.
Title: Re: Errors when installing and removing a package
Post by: scripple on March 13, 2014, 11:12:46 am
Just confirmed that not owning the .tgz file itself wasn't the problem.  Actually you don't even have to install the package to make it happen.  Just clicking on install and seeing the test page generates the errors even if you cancel after the tests without actually installing the mod.

Not sure what's different on my box.   Probably the same thing that gives me a failure on install (themes point to localhost instead of the https url of the forum and I get the host "" errors all the time in the web error log.
Title: Re: Errors when installing and removing a package
Post by: scripple on March 13, 2014, 11:24:23 am
Line 1792 debug output, printing $strPath

.tar.gz file
.../elkarte/packages/temp
.../elkarte/packages
.../elkarte/packages/temp/sources//
.../elkarte/packages/temp/sources
.../elkarte/packages/temp
.../elkarte/packages/temp/sources
.../elkarte/sources/subs

.zip file
.../elkarte/packages/temp
.../elkarte/packages
.../elkarte/packages/temp/spuds_-elk_hideusernames-3bbba4f9bd00/
.../elkarte/packages/temp
.../elkarte/packages/temp/spuds_-elk_hideusernames-3bbba4f9bd00
.../elkarte/packages/temp/spuds_-elk_hideusernames-3bbba4f9bd00
.../elkarte/packages/temp/spuds_-elk_hideusernames-3bbba4f9bd00
.../elkarte/packages/temp/spuds_-elk_hideusernames-3bbba4f9bd00
.../elkarte/packages/temp/spuds_-elk_hideusernames-3bbba4f9bd00
.../elkarte/packages/temp/spuds_-elk_hideusernames-3bbba4f9bd00
.../elkarte/packages/temp/spuds_-elk_hideusernames-3bbba4f9bd00
.../elkarte/packages/temp/spuds_-elk_hideusernames-3bbba4f9bd00/sources/
.../elkarte/packages/temp/spuds_-elk_hideusernames-3bbba4f9bd00
.../elkarte/packages/temp/spuds_-elk_hideusernames-3bbba4f9bd00/sources
.../elkarte/packages/temp/spuds_-elk_hideusernames-3bbba4f9bd00
.../elkarte/sources/subs

The ... expand to the same correct path to the forum root on my host.  This is using the hide... I attached and the .zip downloaded from your site.
Title: Re: Errors when installing and removing a package
Post by: Spuds on March 13, 2014, 11:25:56 am
Not sure ... the double errors is due to the way the pacakge manager works, it does a test install where its checking permissions etc so it can determine if you will need or not to enter some FTP credentials to actually install.

the error is in the function mktree in the Package.subs.php file.  Its as you log says at line 1792 if (is_dir($strPath)) ... you could add var_dump($strPath); before that line to see what its being passed, maybe that will give us more to work on.

Never mind, you beat me to it  :D
Title: Re: Errors when installing and removing a package
Post by: scripple on March 13, 2014, 11:31:05 am
And at line 216, no output at all in the zip version and in the .tar.gz I get

$destination = ...elkarte/packages/temp
$current['filename'] = sources//

And possible unrelated bug, when I went to the post screen the it warned me you had posted while I was posting the subject line go deleted as it complained when I went to post.
Title: Re: Errors when installing and removing a package
Post by: Spuds on March 13, 2014, 11:51:57 am
Quote from: scripple – And at line 216, no output at all in the zip version and in the .tar.gz I get

$destination = ...elkarte/packages/temp
$current['filename'] = sources//
destination looks fine, need to figure out why you are getting a // on the filename, that is not correct (should just be sources/).  I've tried this now on 3 systems with no problems so something odd is going on for sure.
Quote from: scripple – And possible unrelated bug, when I went to the post screen the it warned me you had posted while I was posting the subject line go deleted as it complained when I went to post.
I've seen this one before as well :(
Title: Re: Errors when installing and removing a package
Post by: Spuds on March 13, 2014, 12:01:30 pm
Just backing up in the code to line 180, trying to see why you get an extra '/'
Code: [Select]
if ($current['type'] == 5 && substr($current['filename'], -1) != '/')
 $current['filename'] .= '/';

That could add in an extra '/' but it should not do it if thats already there, could you print out the $current['filename'] at that point as well ... type 5 is a directory type as defined by the tar header.

ETA: for me its string(12) "language.xml" string(11) "license.txt" string(16) "package-info.xml" string(9) "readme.md" string(10) "readme.txt" string(12) "redirect.txt" string(19) "remove_settings.php" string(8) "sources/" string(30) "sources/hideusernames.subs.php" string(13) "uninstall.txt" string(12) "language.xml" string(11) "license.txt" string(16) "package-info.xml"
Title: Re: Errors when installing and removing a package
Post by: scripple on March 13, 2014, 03:17:51 pm
Sorry but I probably won't be able to get more debug until tomorrow.  Maybe very late tonight.
Title: Re: Errors when installing and removing a package
Post by: scripple on March 14, 2014, 01:16:10 am
Ok, I think I found the problem problem, but I'm not enough of a php coder to be sure of the fix.  At line 180, after all the files actually in the tgz file have printed correctly (including the directory with a / already there) there is one more entry.

Code: [Select]
$current = Array
(
    [filename] =>
    [mode] =>
    [uid] =>
    [gid] =>
    [size] =>
    [mtime] =>
    [checksum] =>
    [type] =>
    [linkname] =>
    [magic] =>
    [version] =>
    [uname] =>
    [gname] =>
    [devmajor] =>
    [devminor] =>
    [path] =>
)

This doesn't seem unexpected given this a little above line 180

Code: [Select]
    // Blank record?  This is probably at the end of the file.
    if (empty($current['filename']))
    {
      $offset += 512;
      continue;
    }

But empty($current['filename']) is returning false for that record.  Probably because the unpack above is unpacking it as a100 which fits with strlen($current['filename']) returning 100 when I print it.  100 spaces or other unprintable characters I guess?   So probably a test other than empty needs to be used for the blank record.

I'm not sure why this is the case for me but not you though.
Title: Re: Errors when installing and removing a package
Post by: Spuds on March 14, 2014, 09:59:14 am
Thanks !

Looking at the code, one thing I want to try is to move the sanitizing step first and then the checks after.  So right now its
Code: (current) [Select]
	if (empty($current['filename']))
{
$offset += 512;
continue;
}

if ($current['type'] == 5 && substr($current['filename'], -1) != '/')
$current['filename'] .= '/';

foreach ($current as $k => $v)
{
if (in_array($k, $octdec))
$current[$k] = octdec(trim($v));
else
$current[$k] = trim($v);
}
lets reorder that to
Code: (repalce with) [Select]
		foreach ($current as $k => $v)
{
if (in_array($k, $octdec))
$current[$k] = octdec(trim($v));
else
$current[$k] = trim($v);
}

// Blank record?  This is probably at the end of the file.
if (empty($current['filename']))
{
$offset += 512;
continue;
}

if ($current['type'] == 5 && substr($current['filename'], -1) != '/')
$current['filename'] .= '/';

This places the trim of the array values and the octdec conversion first .. then the next to checks should have clean data.  If it still fails at that point we will need to see if there are other than blanks in those fields.
Title: Re: Errors when installing and removing a package
Post by: scripple on March 14, 2014, 10:18:16 am
That worked on my package and yours.  No more blank entries in the list at 180ish and no more errors in the log.
Title: Re: Errors when installing and removing a package
Post by: Spuds on March 14, 2014, 10:42:30 am
Awesome ! .. I'll add it to a PR and get it merged in.

Thank you for you help in debugging this :D