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 3 : 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 :
36 3 : file_count = 0;
37 3 : file_size = 0;
38 3 : link_count = 0;
39 :
40 3 : msg_progress("Listing...\n");
41 :
42 : /* for each disk */
43 21 : for (i = state->disklist; i != 0; i = i->next) {
44 : tommy_node* j;
45 18 : struct snapraid_disk* disk = i->data;
46 :
47 : /* sort by name */
48 18 : tommy_list_sort(&disk->filelist, file_path_compare);
49 :
50 : /* for each file */
51 16997 : for (j = disk->filelist; j != 0; j = j->next) {
52 16979 : struct snapraid_file* file = j->data;
53 : #if HAVE_LOCALTIME_R
54 : struct tm tm_res;
55 : #endif
56 : struct tm* tm;
57 : time_t t;
58 :
59 16979 : ++file_count;
60 16979 : file_size += file->size;
61 :
62 16979 : log_tag("file:%s:%s:%" PRIu64 ":%" PRIi64 ":%u:%" PRIi64 "\n", disk->name, esc(file->sub), file->size, file->mtime_sec, file->mtime_nsec, file->inode);
63 :
64 16979 : t = file->mtime_sec;
65 : #if HAVE_LOCALTIME_R
66 16979 : tm = localtime_r(&t, &tm_res);
67 : #else
68 : tm = localtime(&t);
69 : #endif
70 :
71 16979 : printf("%12" PRIu64 " ", file->size);
72 16979 : if (tm) {
73 16979 : printf("%04u/%02u/%02u %02u:%02u", tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min);
74 16979 : if (msg_level >= MSG_VERBOSE)
75 16979 : printf(":%02u.%03u", tm->tm_sec, file->mtime_nsec / 1000000);
76 16979 : printf(" ");
77 : }
78 16979 : printf("%s%s\n", disk->dir, file->sub);
79 : }
80 :
81 : /* sort by name */
82 18 : tommy_list_sort(&disk->linklist, link_alpha_compare);
83 :
84 : /* for each link */
85 607 : for (j = disk->linklist; j != 0; j = j->next) {
86 589 : struct snapraid_link* link = j->data;
87 : const char* type;
88 :
89 589 : switch (link->flag & FILE_IS_LINK_MASK) {
90 6 : case FILE_IS_HARDLINK : type = "hardlink"; break;
91 583 : case FILE_IS_SYMLINK : type = "symlink"; break;
92 0 : case FILE_IS_SYMDIR : type = "symdir"; break;
93 0 : case FILE_IS_JUNCTION : type = "junction"; break;
94 : /* LCOV_EXCL_START */
95 : default : type = "unknown"; break;
96 : /* LCOV_EXCL_STOP */
97 : }
98 :
99 589 : ++link_count;
100 :
101 589 : log_tag("link_%s:%s:%s:%s\n", type, disk->name, esc(link->sub), esc(link->linkto));
102 :
103 589 : printf("%12s ", type);
104 589 : printf(" ");
105 589 : if (msg_level >= MSG_VERBOSE)
106 589 : printf(" ");
107 589 : printf("%s%s -> %s%s\n", disk->dir, link->sub, disk->dir, link->linkto);
108 : }
109 : }
110 :
111 3 : msg_status("\n");
112 3 : msg_status("%8u files, for %" PRIu64 " GB\n", file_count, file_size / GIGA);
113 3 : msg_status("%8u links\n", link_count);
114 :
115 3 : log_tag("summary:file_count:%u\n", file_count);
116 3 : log_tag("summary:file_size:%" PRIu64 "\n", file_size);
117 3 : log_tag("summary:link_count:%u\n", link_count);
118 3 : log_tag("summary:exit:ok\n");
119 3 : log_flush();
120 3 : }
121 :
|