xref: /aoo42x/main/solenv/bin/cleanzip.pl (revision 953605d5)
1*953605d5SPedro Giffuni#!/usr/bin/perl -w
27e90fac2SAndrew Rist#**************************************************************
37e90fac2SAndrew Rist#
47e90fac2SAndrew Rist#  Licensed to the Apache Software Foundation (ASF) under one
57e90fac2SAndrew Rist#  or more contributor license agreements.  See the NOTICE file
67e90fac2SAndrew Rist#  distributed with this work for additional information
77e90fac2SAndrew Rist#  regarding copyright ownership.  The ASF licenses this file
87e90fac2SAndrew Rist#  to you under the Apache License, Version 2.0 (the
97e90fac2SAndrew Rist#  "License"); you may not use this file except in compliance
107e90fac2SAndrew Rist#  with the License.  You may obtain a copy of the License at
117e90fac2SAndrew Rist#
127e90fac2SAndrew Rist#    http://www.apache.org/licenses/LICENSE-2.0
137e90fac2SAndrew Rist#
147e90fac2SAndrew Rist#  Unless required by applicable law or agreed to in writing,
157e90fac2SAndrew Rist#  software distributed under the License is distributed on an
167e90fac2SAndrew Rist#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
177e90fac2SAndrew Rist#  KIND, either express or implied.  See the License for the
187e90fac2SAndrew Rist#  specific language governing permissions and limitations
197e90fac2SAndrew Rist#  under the License.
207e90fac2SAndrew Rist#
217e90fac2SAndrew Rist#**************************************************************
227e90fac2SAndrew Rist
237e90fac2SAndrew 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