/usr/bin/gnupod_check is in gnupod-tools 0.99.8-2.1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
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 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 | #!/usr/bin/perl
# Copyright (C) 2002-2007 Adrian Ulrich <pab at blinkenlights.ch>
# Part of the gnupod-tools collection
#
# URL: http://www.gnu.org/software/gnupod/
#
# GNUpod is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# GNUpod is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.#
#
# iTunes and iPod are trademarks of Apple
#
# This product is not supported/written/published by Apple!
use strict;
use GNUpod::XMLhelper;
use GNUpod::FooBar;
use Getopt::Long;
use File::Glob ':glob';
use vars qw(%opts %TRACKER);
#Get maximal Pathlength from XMLHelper constant
my $xmlhelper_maxpathlen = GNUpod::XMLhelper::MAX_PATHLENGTH;
print "gnupod_check Version 0.99.8 (C) Adrian Ulrich\n";
$opts{mount} = $ENV{IPOD_MOUNTPOINT};
#Don't add xml and itunes opts.. we *NEED* the mount opt to be set..
GetOptions(\%opts, "version", "help|h", "mount|m=s", "fixit");
GNUpod::FooBar::GetConfig(\%opts, {mount=>'s', 'automktunes'=>'b', model=>'s'}, "gnupod_check");
usage() if $opts{help};
version() if $opts{version};
# Need this global :-(
my $con = GNUpod::FooBar::connect(\%opts);
go();
####################################################
# Worker
sub go {
usage($con->{status}."\n") if $con->{status};
print "Pass 1: Checking Files in the GNUtunesDB.xml...\n";
GNUpod::XMLhelper::doxml($con->{xml}) or usage("Failed to parse $con->{xml}, did you run gnupod_INIT?\n");
print "Pass 2: Checking Files on the iPod...\n";
checkGNUtunes($con);
print "..finished\n\n";
print " Total Playtime : ".int($TRACKER{TIME}/1000/60/60)." h\n";
printf (" Space used : %.2f GB\n",( $TRACKER{SIZE}/1024/1024/1024 ) );
print " iPod files : $TRACKER{GLOBFILES}\n";
print " GNUpod files : $TRACKER{ITFILES}\n";
if($opts{fixit}) {
if($TRACKER{FIXED}) {
print " -> Writing new GNUtunesDB.xml, i fixed $TRACKER{FIXED} Errors.\n";
print " You may have to re-run $0\n";
GNUpod::XMLhelper::writexml($con, {automktunes=>$opts{automktunes}});
}
else {
print " -> Nothing fixed, no need to rewrite the GNUtunesDB.xml\n";
}
}
else {
if($TRACKER{GLOBFILES} == $TRACKER{ITFILES} && $TRACKER{ERR} == 0) {
print " -> Everything is fine :)\n";
}
elsif($TRACKER{GLOBFILES} != $TRACKER{ITFILES}) {
print " -> The GNUtunesDB.xml is inconsistent. Please try to fix the errors or run $0 --fixit\n";
print " (Note: --fixit removes 'stale' files on the iPod)\n";
}
if($TRACKER{ERR} > 25) {
print " -> I found MANY ($TRACKER{ERR}) errors. Maybe you should run\n";
print " '$0 --fixit' to let me fix this errors. If it still doesn't help, run\n";
print " 'gnupod_addsong --restore'. This would wipe all your Playlists\n";
print " but would cure your iPod for sure.\n";
}
}
}
############################################
# Glob all files
sub checkGNUtunes {
my($c) = @_;
foreach my $file (bsd_glob($c->{musicdir}."/*/*", GLOB_NOSORT)) {
next if -d $file;
$TRACKER{GLOBFILES}++;
unless($TRACKER{PATH}{lc($file)}) { #Hmpf.. file maybe not in the GNUtunesDB
print " Stale file '$file' found. Remove the file, it wastes space...\n";
$TRACKER{ERR}++;
if($opts{fixit}) {
print " fixit: Removing $file\n";
unlink($file) or warn "Could not unlink $file, $!\n";
$TRACKER{FIXED}++;
}
}
}
}
#############################################
# Eventhandler for FILE items
sub newfile {
my($el) = @_;
#Add song to xml?
my $call_mkfile = $opts{fixit};
my $rp = GNUpod::XMLhelper::realpath($opts{mount},$el->{file}->{path});
my $id = $el->{file}->{id};
my $HINT = "Run 'gnupod_check --fixit' to wipe this zombie";
$TRACKER{SIZE}+=int($el->{file}->{filesize});
$TRACKER{TIME}+=int($el->{file}->{time});
$TRACKER{ID}{int($id)}++;
$TRACKER{PATH}{lc($rp)}++; #FAT32 is caseInsensitive.. HFS+ should also be caseInsensitive (ON THE IPOD)
$TRACKER{ITFILES}++;
if($TRACKER{ID}{int($id)} != 1) {
print " ID $id is used ".int($TRACKER{ID}{int($id)})." times!\n";
$TRACKER{ERR}++;
if($opts{fixit}) {
print " fixit: Removing this file from XML, re-run $0 to get rid of the stale file!\n";
$call_mkfile = undef;
$TRACKER{FIXED}++;
}
}
if(int($id) < 1) {
print " ID $id is < 1 .. You shouldn't do this!\n";
$TRACKER{ERR}++;
if($opts{fixit}) {
print " fixit: Removing this file from XML, re-run $0 to get rid of the stale file!\n";
$call_mkfile = undef;
$TRACKER{FIXED}++;
}
}
if(length($el->{file}->{path}) > $xmlhelper_maxpathlen) {
print " ID $id has a long filename. Some iPods may refuse to play this file with recent firmware! Run $0 --fixit\n";
$TRACKER{ERR}++;
if($opts{fixit}) {
my($ipod_path, $real_path) = GNUpod::XMLhelper::getpath($con,$rp);
if($ipod_path) {
print " fixit: Renaming $rp into $real_path\n";
my $rename_result = rename($rp,$real_path);
if($rename_result) {
$el->{file}->{path} = $ipod_path;
$TRACKER{PATH}{lc($rp)}--;
$TRACKER{PATH}{lc($real_path)}++;
$rp = $real_path;
}
else {
print " fixit: Ouch, rename failed: $!\n";
}
}
else {
print " fixit: Ouch, no new path found for $rp, removing from xml\n";
$call_mkfile = undef;
}
$TRACKER{FIXED}++;
}
}
if(!-e $rp) {
print " ID $id vanished! ($rp) -> $HINT\n";
$TRACKER{ERR}++;
if($opts{fixit}) {
print " fixit: Removing $id from XML Database\n";
$call_mkfile = undef;
$TRACKER{FIXED}++;
}
}
elsif(-d $rp) {
print " ID $id is a DIRECTORY?! ($rp)\n";
if($opts{fixit}) {
print " fixit: Removing $id from XML Database\n";
$call_mkfile = undef;
$TRACKER{FIXED}++;
}
}
elsif(-s $rp < 1) {
print " ID $id has zero size! ($rp) -> $HINT\n";
$TRACKER{ERR}++;
if($opts{fixit}) {
print " fixit: Removing $id from XML Database, please re-run $0 to get rid of the stale file!\n";
$call_mkfile = undef;
$TRACKER{FIXED}++;
}
}
GNUpod::XMLhelper::mkfile($el) if $call_mkfile;
}
############################################
# Eventhandler for PLAYLIST items
sub newpl {
my($el, $name, $plt) = @_;
#Do something with $el - holds playlist stuff :)
GNUpod::XMLhelper::mkfile($el,{$plt."name"=>$name});
}
###############################################################
# Basic help
sub usage {
my($rtxt) = @_;
die << "EOF";
$rtxt
Usage: gnupod_check [-h] [-m directory]
gnupod_check checks for 'lost' files
-h, --help display this help and exit
--version output version information and exit
-m, --mount=directory iPod mountpoint, default is \$IPOD_MOUNTPOINT
--fixit Try to fixup some errors (may delete 'lost' files)
Report bugs to <bug-gnupod\@nongnu.org>
EOF
}
sub version {
die << "EOF";
gnupod_check (gnupod) 0.99.8
Copyright (C) Adrian Ulrich 2002-2004
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
EOF
}
|