Line data Source code
1 : /*
2 : * Copyright (C) 2013 Andrea Mazzoleni
3 : *
4 : * This program is free software: you can redistribute it and/or modify
5 : * it under the terms of the GNU General Public License as published by
6 : * the Free Software Foundation, either version 3 of the License, or
7 : * (at your option) any later version.
8 : *
9 : * This program is distributed in the hope that it will be useful,
10 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 : * GNU General Public License for more details.
13 : *
14 : * You should have received a copy of the GNU General Public License
15 : * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 : */
17 :
18 : #include "portable.h"
19 :
20 : #include "util.h"
21 : #include "elem.h"
22 : #include "state.h"
23 : #include "parity.h"
24 : #include "handle.h"
25 :
26 : /****************************************************************************/
27 : /* list */
28 :
29 5 : void state_list(struct snapraid_state* state)
30 : {
31 : tommy_node* i;
32 : unsigned file_count;
33 : data_off_t file_size;
34 : unsigned link_count;
35 : char esc_buffer[ESC_MAX];
36 : char esc_buffer_alt[ESC_MAX];
37 :
38 5 : file_count = 0;
39 5 : file_size = 0;
40 5 : link_count = 0;
41 :
42 5 : msg_progress("Listing...\n");
43 :
44 : /* for each disk */
45 35 : for (i = state->disklist; i != 0; i = i->next) {
46 : tommy_node* j;
47 30 : struct snapraid_disk* disk = i->data;
48 :
49 : /* sort by name */
50 30 : tommy_list_sort(&disk->filelist, file_path_compare);
51 :
52 : /* for each file */
53 39578 : for (j = disk->filelist; j != 0; j = j->next) {
54 39548 : struct snapraid_file* file = j->data;
55 : #if HAVE_LOCALTIME_R
56 : struct tm tm_res;
57 : #endif
58 : struct tm* tm;
59 : time_t t;
60 :
61 39548 : ++file_count;
62 39548 : file_size += file->size;
63 :
64 39548 : log_tag("file:%s:%s:%" PRIu64 ":%" PRIi64 ":%u:%" PRIi64 "\n", disk->name, esc_tag(file->sub, esc_buffer), file->size, file->mtime_sec, file->mtime_nsec, file->inode);
65 :
66 39548 : t = file->mtime_sec;
67 : #if HAVE_LOCALTIME_R
68 39548 : tm = localtime_r(&t, &tm_res);
69 : #else
70 : tm = localtime(&t);
71 : #endif
72 :
73 39548 : printf("%12" PRIu64 " ", file->size);
74 39548 : if (tm) {
75 39548 : printf("%04u/%02u/%02u %02u:%02u", tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min);
76 39548 : if (msg_level >= MSG_VERBOSE)
77 39548 : printf(":%02u.%03u", tm->tm_sec, file->mtime_nsec / 1000000);
78 39548 : printf(" ");
79 : }
80 39548 : printf("%s\n", fmt_term(disk, file->sub, esc_buffer));
81 : }
82 :
83 : /* sort by name */
84 30 : tommy_list_sort(&disk->linklist, link_alpha_compare);
85 :
86 : /* for each link */
87 1375 : for (j = disk->linklist; j != 0; j = j->next) {
88 1345 : struct snapraid_link* slink = j->data;
89 : const char* type;
90 :
91 1345 : switch (slink->flag & FILE_IS_LINK_MASK) {
92 9 : case FILE_IS_HARDLINK : type = "hardlink"; break;
93 1336 : case FILE_IS_SYMLINK : type = "symlink"; break;
94 0 : case FILE_IS_SYMDIR : type = "symdir"; break;
95 0 : case FILE_IS_JUNCTION : type = "junction"; break;
96 : /* LCOV_EXCL_START */
97 : default : type = "unknown"; break;
98 : /* LCOV_EXCL_STOP */
99 : }
100 :
101 1345 : ++link_count;
102 :
103 1345 : log_tag("link_%s:%s:%s:%s\n", type, disk->name, esc_tag(slink->sub, esc_buffer), esc_tag(slink->linkto, esc_buffer_alt));
104 :
105 1345 : printf("%12s ", type);
106 1345 : printf(" ");
107 1345 : if (msg_level >= MSG_VERBOSE)
108 1345 : printf(" ");
109 1345 : printf("%s -> %s\n", fmt_term(disk, slink->sub, esc_buffer), fmt_term(disk, slink->linkto, esc_buffer_alt));
110 : }
111 : }
112 :
113 5 : msg_status("\n");
114 5 : msg_status("%8u files, for %" PRIu64 " GB\n", file_count, file_size / GIGA);
115 5 : msg_status("%8u links\n", link_count);
116 :
117 5 : log_tag("summary:file_count:%u\n", file_count);
118 5 : log_tag("summary:file_size:%" PRIu64 "\n", file_size);
119 5 : log_tag("summary:link_count:%u\n", link_count);
120 5 : log_tag("summary:exit:ok\n");
121 5 : log_flush();
122 5 : }
123 :
|