~ubuntu-branches/ubuntu/vivid/cctools/vivid

« back to all changes in this revision

Viewing changes to s3tools/src/s3ls.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Hanke
  • Date: 2011-05-07 09:05:00 UTC
  • Revision ID: james.westby@ubuntu.com-20110507090500-lqpmdtwndor6e7os
Tags: upstream-3.3.2
ImportĀ upstreamĀ versionĀ 3.3.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
Copyright (C) 2010- The University of Notre Dame
 
3
This software is distributed under the GNU General Public License.
 
4
See the file COPYING for details.
 
5
*/
 
6
#include <stdio.h>
 
7
#include <stdlib.h>
 
8
#include <string.h>
 
9
#include <stringtools.h>
 
10
#include <time.h>
 
11
#include <unistd.h>
 
12
 
 
13
#include "s3common.h"
 
14
#include "s3c_bucket.h"
 
15
 
 
16
int main(int argc, char** argv) {
 
17
        struct list *dirents;
 
18
        struct s3_dirent_object *d;
 
19
        char long_list = 0;
 
20
        char c;
 
21
        int i;
 
22
 
 
23
        opterr = 0;
 
24
        s3_initialize(&argc, argv);
 
25
 
 
26
        while( (c = getopt(argc, argv, "l")) != -1 ) {
 
27
                switch(c) {
 
28
                        case 'l':
 
29
                                long_list = 1;
 
30
                                break;
 
31
                        default:
 
32
                                fprintf(stderr, "Error: invalid option (-%c)\n", optopt);
 
33
                }
 
34
        }
 
35
 
 
36
        if(optind >= argc) {
 
37
                fprintf(stderr, "usage: s3ls [-l] <bucket>\n");
 
38
                return -1;
 
39
        }
 
40
 
 
41
        dirents = list_create();
 
42
        for(i = optind; i < argc; i++) {
 
43
                char date[1024];
 
44
                if(argc-optind > 1) printf("%s:\n", argv[i]);
 
45
                s3_ls_bucket(argv[i], dirents, s3_userid(), s3_key());
 
46
                while( (d = list_pop_head(dirents)) ) {
 
47
                        strftime(date, 1024, "%b %d %H:%M", localtime(&d->last_modified));
 
48
                        if(!long_list) printf("%s\n", d->key);
 
49
                        else printf("-rw-------  1 %s\t%9d %s %s\n", d->display_name, d->size, date, d->key);
 
50
                        free(d->display_name);
 
51
                        free(d);
 
52
                        d = NULL;
 
53
                }
 
54
        }
 
55
        list_delete(dirents);
 
56
 
 
57
        return 0;
 
58
}
 
59