2 #*************************************************************************
4 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 # Copyright 2008 by Sun Microsystems, Inc.
8 # OpenOffice.org - a multi-platform office productivity suite
10 # $RCSfile: cleanzip.pl,v $
14 # This file is part of OpenOffice.org.
16 # OpenOffice.org is free software: you can redistribute it and/or modify
17 # it under the terms of the GNU Lesser General Public License version 3
18 # only, as published by the Free Software Foundation.
20 # OpenOffice.org is distributed in the hope that it will be useful,
21 # but WITHOUT ANY WARRANTY; without even the implied warranty of
22 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 # GNU Lesser General Public License version 3 for more details
24 # (a copy is included in the LICENSE file that accompanied this code).
26 # You should have received a copy of the GNU Lesser General Public License
27 # version 3 along with OpenOffice.org. If not, see
28 # <http://www.openoffice.org/license.html>
29 # for a copy of the LGPLv3 License.
31 #*************************************************************************
35 print "Cleanup unwanted unix attributes in zip archives\n\n";
37 print "$0 archive\n\n";
41 usage
() if ! defined $ARGV[0];
43 my $filename = $ARGV[0];
44 use Archive
::Zip
qw(:ERROR_CODES :CONSTANTS);
45 my $zip = Archive
::Zip
->new();
47 unless ( $zip->read( $filename ) == AZ_OK
) {
48 die "$0: ERROR reading $filename\n";
50 my @members = $zip ->members();
52 foreach my $member ( @members ) {
53 # printf ( "%o\n",$member->unixFileAttributes());
54 # printf ( "%o\n",$member->unixFileAttributes() & 0b111111111111);
55 my $attribs = $member->unixFileAttributes();
56 if ( $member->isDirectory ) {
57 $attribs = $attribs & 0b101111111111
;
58 $member->unixFileAttributes($attribs)
60 # printf ( "%o\n",$member->unixFileAttributes());
61 # printf ( "%o\n",$member->unixFileAttributes() & 0b111111111111);
62 # print ( $member->fileName()."\n");
64 unless ( $zip->writeToFileNamed( ${filename
}."_new" ) == AZ_OK
) {
65 die "$0: ERROR reading ${filename}_new\n";
67 rename($filename."_new", $filename);