LCOV - code coverage report
Current view: top level - cmdline - list.c (source / functions) Hit Total Coverage
Test: lcov.info Lines: 44 48 91.7 %
Date: 2026-04-29 15:04:44 Functions: 1 1 100.0 %

          Line data    Source code
       1             : // SPDX-License-Identifier: GPL-3.0-or-later
       2             : // Copyright (C) 2013 Andrea Mazzoleni
       3             : 
       4             : #include "portable.h"
       5             : 
       6             : #include "util.h"
       7             : #include "elem.h"
       8             : #include "state.h"
       9             : #include "parity.h"
      10             : #include "handle.h"
      11             : 
      12             : /****************************************************************************/
      13             : /* list */
      14             : 
      15           5 : void state_list(struct snapraid_state* state)
      16             : {
      17             :         tommy_node* i;
      18             :         unsigned file_count;
      19             :         data_off_t file_size;
      20             :         unsigned link_count;
      21             :         char esc_buffer[ESC_MAX];
      22             :         char esc_buffer_alt[ESC_MAX];
      23             : 
      24           5 :         file_count = 0;
      25           5 :         file_size = 0;
      26           5 :         link_count = 0;
      27             : 
      28           5 :         msg_progress("Listing...\n");
      29             : 
      30             :         /* for each disk */
      31          35 :         for (i = state->disklist; i != 0; i = i->next) {
      32             :                 tommy_node* j;
      33          30 :                 struct snapraid_disk* disk = i->data;
      34             : 
      35             :                 /* sort by name */
      36          30 :                 tommy_list_sort(&disk->filelist, file_path_compare);
      37             : 
      38             :                 /* for each file */
      39       39578 :                 for (j = disk->filelist; j != 0; j = j->next) {
      40       39548 :                         struct snapraid_file* file = j->data;
      41             : #if HAVE_LOCALTIME_R
      42             :                         struct tm tm_res;
      43             : #endif
      44             :                         struct tm* tm;
      45             :                         time_t t;
      46             : 
      47       39548 :                         ++file_count;
      48       39548 :                         file_size += file->size;
      49             : 
      50       39548 :                         if (state->opt.gui_verbose)
      51           0 :                                 log_tag("file:%s:%s:%" PRIu64 ":%" PRIi64 ":%u:%" PRIu64 "\n", disk->name, esc_tag(file->sub, esc_buffer), file->size, file->mtime_sec, file->mtime_nsec, file->inode);
      52             : 
      53       39548 :                         t = file->mtime_sec;
      54             : #if HAVE_LOCALTIME_R
      55       39548 :                         tm = localtime_r(&t, &tm_res);
      56             : #else
      57             :                         tm = localtime(&t);
      58             : #endif
      59             : 
      60       39548 :                         printf("%12" PRIu64 " ", file->size);
      61       39548 :                         if (tm) {
      62       39548 :                                 printf("%04u/%02u/%02u %02u:%02u", tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min);
      63       39548 :                                 if (msg_level >= MSG_VERBOSE)
      64       39548 :                                         printf(":%02u.%09u", tm->tm_sec, file->mtime_nsec);
      65       39548 :                                 printf(" ");
      66             :                         }
      67       39548 :                         printf("%s\n", fmt_term(disk, file->sub, esc_buffer));
      68             :                 }
      69             : 
      70             :                 /* sort by name */
      71          30 :                 tommy_list_sort(&disk->linklist, link_alpha_compare);
      72             : 
      73             :                 /* for each link */
      74        1375 :                 for (j = disk->linklist; j != 0; j = j->next) {
      75        1345 :                         struct snapraid_link* slink = j->data;
      76             :                         const char* type;
      77             : 
      78        1345 :                         switch (slink->flag & FILE_IS_LINK_MASK) {
      79           9 :                         case FILE_IS_HARDLINK : type = "hardlink"; break;
      80        1336 :                         case FILE_IS_SYMLINK : type = "symlink"; break;
      81           0 :                         case FILE_IS_SYMDIR : type = "symdir"; break;
      82           0 :                         case FILE_IS_JUNCTION : type = "junction"; break;
      83             :                         /* LCOV_EXCL_START */
      84             :                         default : type = "unknown"; break;
      85             :                                 /* LCOV_EXCL_STOP */
      86             :                         }
      87             : 
      88        1345 :                         ++link_count;
      89             : 
      90        1345 :                         if (state->opt.gui_verbose)
      91           0 :                                 log_tag("link_%s:%s:%s:%s\n", type, disk->name, esc_tag(slink->sub, esc_buffer), esc_tag(slink->linkto, esc_buffer_alt));
      92             : 
      93        1345 :                         printf("%12s ", type);
      94        1345 :                         printf("                 ");
      95        1345 :                         if (msg_level >= MSG_VERBOSE)
      96        1345 :                                 printf("             ");
      97        1345 :                         printf("%s -> %s\n", fmt_term(disk, slink->sub, esc_buffer), fmt_term(disk, slink->linkto, esc_buffer_alt));
      98             :                 }
      99             :         }
     100             : 
     101           5 :         msg_status("\n");
     102           5 :         msg_status("%8u files, for %" PRIu64 " GB\n", file_count, file_size / GIGA);
     103           5 :         msg_status("%8u links\n", link_count);
     104             : 
     105           5 :         log_tag("summary:file_count:%u\n", file_count);
     106           5 :         log_tag("summary:file_size:%" PRIu64 "\n", file_size);
     107           5 :         log_tag("summary:link_count:%u\n", link_count);
     108           5 :         log_tag("summary:exit:ok\n");
     109           5 :         log_flush();
     110           5 : }
     111             : 

Generated by: LCOV version 1.0