Checking in changes prior to tagging of version 2.30.
[MogileFS-Utils.git] / mogfileinfo
blob2fd596150fababfd1657f86958a9dfd8c882ea2a
1 #!/usr/bin/perl
3 =head1 NAME
5 mogfileinfo -- Fetch key metadata from a MogileFS installation
7 =head1 SYNOPSIS
9 $ mogfileinfo --trackers=host --domain=foo --key="/hello.jpg"
11 =head1 OPTIONS
13 =over
15 =item --trackers=host1:7001,host2:7001
17 Use these MogileFS trackers to negotiate with.
19 =item --domain=<domain>
21 Set the MogileFS domain to use.
23 =item --key="<key>"
25 The key to inspect. Can be an arbitrary string.
27 =back
29 =head1 AUTHOR
31 Dormando E<lt>L<dormando@rydia.net>E<gt>
33 =head1 BUGS
35 None known, but output might change in the future.
37 =head1 LICENSE
39 Licensed for use and redistribution under the same terms as Perl itself.
41 =cut
43 use strict;
44 use warnings;
46 use lib './lib';
47 use MogileFS::Utils;
49 my $util = MogileFS::Utils->new;
50 my $usage = "--trackers=host --domain=foo --key='/hello.jpg'";
51 my $c = $util->getopts($usage, 'key=s');
53 my $mogc = $util->client;
55 my $fid = $mogc->file_info($c->{key});
56 if ($mogc->errcode) {
57 die "Error fetching file info: " . $mogc->errstr;
59 die "Key not found: " . $c->{key} unless $fid;
61 # Might replace this with just fetching the devids from above...
62 my @paths = $mogc->get_paths($c->{key}, { noverify => 1, pathcount => 99 });
63 if ($mogc->errcode) {
64 die "Error fetching paths: " . $mogc->errstr;
66 die "No paths found or key does not exist" unless @paths;
68 print "- file: ", $c->{key}, "\n";
69 for my $item (sort keys %$fid) {
70 printf(" %8s: %20s\n", $item, $fid->{$item});
73 for my $path (@paths) {
74 print " - ", $path, "\n";