File: s3ls.c

package info (click to toggle)
cctools 3.5.1-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 5,704 kB
  • sloc: ansic: 49,398; cpp: 15,568; perl: 12,324; sh: 2,668; python: 1,422; makefile: 632; yacc: 433; lex: 152; xml: 109
file content (59 lines) | stat: -rw-r--r-- 1,299 bytes parent folder | download
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
/*
Copyright (C) 2010- The University of Notre Dame
This software is distributed under the GNU General Public License.
See the file COPYING for details.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stringtools.h>
#include <time.h>
#include <unistd.h>

#include "s3common.h"
#include "s3c_bucket.h"

int main(int argc, char** argv) {
	struct list *dirents;
	struct s3_dirent_object *d;
	char long_list = 0;
	char c;
	int i;

	opterr = 0;
	s3_initialize(&argc, argv);

	while( (c = getopt(argc, argv, "l")) != (char)-1 ) {
		switch(c) {
			case 'l':
				long_list = 1;
				break;
			default:
				fprintf(stderr, "Error: invalid option (-%c)\n", optopt);
		}
	}

	if(optind >= argc) {
		fprintf(stderr, "usage: s3ls [-l] <bucket>\n");
		return -1;
	}

	dirents = list_create();
	for(i = optind; i < argc; i++) {
		char date[1024];
		if(argc-optind > 1) printf("%s:\n", argv[i]);
		s3_ls_bucket(argv[i], dirents, s3_userid(), s3_key());
		while( (d = list_pop_head(dirents)) ) {
			strftime(date, 1024, "%b %d %H:%M", localtime(&d->last_modified));
			if(!long_list) printf("%s\n", d->key);
			else printf("-rw-------  1 %s\t%9d %s %s\n", d->display_name, d->size, date, d->key);
			free(d->display_name);
			free(d);
			d = NULL;
		}
	}
	list_delete(dirents);

	return 0;
}