-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrm_rsrc
executable file
·83 lines (77 loc) · 1.59 KB
/
rm_rsrc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/perl
#
# rm_rsrc
# == Author(s) : Takuya Otani <takuya.otani@gmail.com> ==
# == Copyright (C) 2012 SimpleBoxes/SerendipityNZ Ltd. ==
sub showUsage
{
my $errMsg = shift;
print STDERR $errMsg,"\n\n" if ($errMsg ne '');
print STDERR << "__END_OF_USAGE__";
Usage: $0 [OPTION] FILE
FILE is a target file. Its resource fork will be removed
Options
-v verbose mode to display resource fork info to be removed.
__END_OF_USAGE__
exit 1;
} # end of sub showUsage
sub parseOption
{
my %options = ();
while ($ARGV[0] =~ /^-/)
{
my $opt = shift @ARGV;
if ($opt eq '-v')
{
$options{'verbose'} = 1;
}
else
{
&showUsage();
}
}
return \%options;
} # end of sub parseOption
sub runMain
{
my $file = shift;
my $option = shift;
if ($file eq '')
{
&showUsage();
}
elsif (!-e $file)
{
&showUsage('The file "' . $file . '" does not exist.');
}
elsif (-d $file)
{
&showUsage('"' . $file . '" is a directory.');
}
print $file . ' : ' if ($option->{'verbose'});
my $fileInfo = `ls -l@ "$file"`;
if ( $fileInfo =~ /[-rwxd]{10}([ @]).+?\n(.+\n)/s
and $1 eq '@')
{
print 'removing resource fork ...' . "\n" if ($option->{'verbose'});
my @rsrcTypes = split(/\n/,$2);
foreach my $type (@rsrcTypes)
{
$type =~ s/^\s+//;
$type =~ s/\s+$//;
$type =~ s/\d+$//;
$type =~ s/\s//g;
`xattr -d "$type" "$file"`;
print ' => removed : ' . $type . "\n" if ($option->{'verbose'});
}
}
else
{
print 'no resource fork' . "\n" if ($option->{'verbose'});
}
} # end of sub runMain
{ # main
my $option = &parseOption();
&runMain($ARGV[0],$option);
}
exit 0;