xref: /aoo41x/main/solenv/bin/cleanzip.pl (revision 7e90fac2)
1cdf0e10cSrcweir#!/usr/bin/perl -w
2*7e90fac2SAndrew Rist#**************************************************************
3*7e90fac2SAndrew Rist#
4*7e90fac2SAndrew Rist#  Licensed to the Apache Software Foundation (ASF) under one
5*7e90fac2SAndrew Rist#  or more contributor license agreements.  See the NOTICE file
6*7e90fac2SAndrew Rist#  distributed with this work for additional information
7*7e90fac2SAndrew Rist#  regarding copyright ownership.  The ASF licenses this file
8*7e90fac2SAndrew Rist#  to you under the Apache License, Version 2.0 (the
9*7e90fac2SAndrew Rist#  "License"); you may not use this file except in compliance
10*7e90fac2SAndrew Rist#  with the License.  You may obtain a copy of the License at
11*7e90fac2SAndrew Rist#
12*7e90fac2SAndrew Rist#    http://www.apache.org/licenses/LICENSE-2.0
13*7e90fac2SAndrew Rist#
14*7e90fac2SAndrew Rist#  Unless required by applicable law or agreed to in writing,
15*7e90fac2SAndrew Rist#  software distributed under the License is distributed on an
16*7e90fac2SAndrew Rist#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17*7e90fac2SAndrew Rist#  KIND, either express or implied.  See the License for the
18*7e90fac2SAndrew Rist#  specific language governing permissions and limitations
19*7e90fac2SAndrew Rist#  under the License.
20*7e90fac2SAndrew Rist#
21*7e90fac2SAndrew Rist#**************************************************************
22*7e90fac2SAndrew Rist
23*7e90fac2SAndrew Rist
24cdf0e10cSrcweir
25cdf0e10cSrcweirsub usage
26cdf0e10cSrcweir{
27cdf0e10cSrcweir	print "Cleanup unwanted unix attributes in zip archives\n\n";
28cdf0e10cSrcweir	print "Usage:\n";
29cdf0e10cSrcweir	print "$0 archive\n\n";
30cdf0e10cSrcweir    exit(1);
31cdf0e10cSrcweir}
32cdf0e10cSrcweir
33cdf0e10cSrcweirusage() if ! defined $ARGV[0];
34cdf0e10cSrcweir
35cdf0e10cSrcweirmy $filename = $ARGV[0];
36cdf0e10cSrcweiruse Archive::Zip qw(:ERROR_CODES :CONSTANTS);
37cdf0e10cSrcweirmy $zip = Archive::Zip->new();
38cdf0e10cSrcweir
39cdf0e10cSrcweirunless ( $zip->read( $filename ) == AZ_OK ) {
40cdf0e10cSrcweir	die "$0: ERROR reading $filename\n";
41cdf0e10cSrcweir}
42cdf0e10cSrcweirmy @members = $zip ->members();
43cdf0e10cSrcweir
44cdf0e10cSrcweirforeach my $member ( @members ) {
45cdf0e10cSrcweir#	printf ( "%o\n",$member->unixFileAttributes());
46cdf0e10cSrcweir#	printf ( "%o\n",$member->unixFileAttributes() & 0b111111111111);
47cdf0e10cSrcweir	my $attribs = $member->unixFileAttributes();
48cdf0e10cSrcweir	if ( $member->isDirectory ) {
49cdf0e10cSrcweir		$attribs = $attribs & 0b101111111111;
50cdf0e10cSrcweir		$member->unixFileAttributes($attribs)
51cdf0e10cSrcweir	}
52cdf0e10cSrcweir#	printf ( "%o\n",$member->unixFileAttributes());
53cdf0e10cSrcweir#	printf ( "%o\n",$member->unixFileAttributes() & 0b111111111111);
54cdf0e10cSrcweir#	print ( $member->fileName()."\n");
55cdf0e10cSrcweir}
56cdf0e10cSrcweirunless ( $zip->writeToFileNamed( ${filename}."_new" ) == AZ_OK ) {
57cdf0e10cSrcweir	die "$0: ERROR reading ${filename}_new\n";
58cdf0e10cSrcweir}
59cdf0e10cSrcweirrename($filename."_new", $filename);
60cdf0e10cSrcweir
61