Unified Agent can't extract zip packages

Bug #1070788 reported by YvesG
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OCS Inventory: Unified Unix Agent
Fix Released
Low
Frank

Bug Description

Hi,

When building an automatic redistribution packages, zip format is used by default. If there is no problem with windows agent, Unified Unix Agent just try to use tar in the build_package function.

I added a little fix to try unzip if tar extraction failed:

In Download.pm file, I replaced

---
 if( system( $common->get_path("tar")." -xvzf $tmp/build.tar.gz -C $tmp") ){
                $logger->error("Cannot extract $id.");
                download_message($id,$messages->{err_build},$logger,$context);
                return 1;
        }
---

with

---
 if( system( $common->get_path("tar")." -xvzf $tmp/build.tar.gz -C $tmp") ){
                $logger->error("Cannot extract $id with tar, trying with unzip.");
                if( system( $common->get_path("unzip")." $tmp/build.tar.gz -d $tmp") ){
                        $logger->error("Cannot extract $id with unzip.");
                        download_message($id,$messages->{err_build},$logger,$context);
                        return 1;
                }
        }
---

Revision history for this message
YvesG (yves-guimard) wrote :
Revision history for this message
Frank (frank-bourdeau) wrote :

Thanks for your patch YvesG.

But I'm little confused. Unzip command can't extract tar.gz archives but only zip archives. So your patch can't run correctly.

Revision history for this message
YvesG (yves-guimard) wrote : Re: [Bug 1070788] Re: Unified Agent can't extract zip packages

Hi Frank,

Yes it works: First it try to uncompress the archive with tar method:
system( $common->get_path("tar")." -xvzf $tmp/build.tar.gz -C $tmp")

If tar command fail, unzip is used :
system( $common->get_path("unzip")." $tmp/build.tar.gz -d $tmp")

If unzip fail too, the program return.

It works because the download method will always use hte name build.tar.gz
to recreate the original package as if the format used before was zip. Here
is the code that recreate the package. You can see that the extension
.tar.gz is always used. Also, unzip look the format of a file, not the
extension.

 for($i=1;$i<=$count;$i++){
        if(-f "./$id/$id-$i"){
            # We make a tmp working directory
            if($i==1){
                open PACKAGE, ">$tmp/build.tar.gz" or return 1;
            }
            # We write each fragment in the final package
            open FRAGMENT, "./$id/$id-$i" or return 1;
            my $row;
            while($row = <FRAGMENT>){
                print PACKAGE $row;
            }
            close(FRAGMENT);
        }else{
            return 1;
        }
    }
    close(PACKAGE);

Tell me if i'm not clear ;-)

Juste au cas ou, si tu es français nous nous comprendrons peut être plus
facilement ;-).

Merci,
Yves

2012/10/31 Frank <email address hidden>

> Thanks for your patch YvesG.
>
> But I'm little confused. Unzip command can't extract tar.gz archives but
> only zip archives. So your patch can't run correctly.
>
> --
> You received this bug notification because you are subscribed to the bug
> report.
> https://bugs.launchpad.net/bugs/1070788
>
> Title:
> Unified Agent can't extract zip packages
>
> Status in OCS Inventory NG Unified Unix Agent:
> New
>
> Bug description:
> Hi,
>
> When building an automatic redistribution packages, zip format is used
> by default. If there is no problem with windows agent, Unified Unix
> Agent just try to use tar in the build_package function.
>
> I added a little fix to try unzip if tar extraction failed:
>
> In Download.pm file, I replaced
>
> ---
> if( system( $common->get_path("tar")." -xvzf $tmp/build.tar.gz -C
> $tmp") ){
> $logger->error("Cannot extract $id.");
>
> download_message($id,$messages->{err_build},$logger,$context);
> return 1;
> }
> ---
>
> with
>
> ---
> if( system( $common->get_path("tar")." -xvzf $tmp/build.tar.gz -C
> $tmp") ){
> $logger->error("Cannot extract $id with tar, trying with
> unzip.");
> if( system( $common->get_path("unzip")."
> $tmp/build.tar.gz -d $tmp") ){
> $logger->error("Cannot extract $id with unzip.");
>
> download_message($id,$messages->{err_build},$logger,$context);
> return 1;
> }
> }
> ---
>
> To manage notifications about this bug go to:
>
> https://bugs.launchpad.net/ocsinventory-unix-agent/+bug/1070788/+subscriptions
>

Frank (frank-bourdeau)
Changed in ocsinventory-unix-agent:
importance: Undecided → Low
status: New → Fix Committed
assignee: nobody → Frank (frank-bourdeau)
mortheres (mortheres)
Changed in ocsinventory-unix-agent:
milestone: none → 2.1rc1
Frank (frank-bourdeau)
Changed in ocsinventory-unix-agent:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.