1
1

add a max modified time, or mtime, view and sorting

This adds an 'm' command to show the latest modified time of all files
in a directory. The 'M' command allows for ascending and descending
mtime sorting. These are only enabled with the -e flag and overload
the dir_ext mtime field.
Этот коммит содержится в:
Alex Wilson 2019-01-20 13:03:38 -07:00 коммит произвёл Yorhel
родитель 2501fb1ad5
Коммит 60fdac0680
8 изменённых файлов: 84 добавлений и 10 удалений

Просмотреть файл

@ -67,6 +67,9 @@ when importing (to read this extra information in memory). This flag has no
effect when importing a file that has been exported without the extended effect when importing a file that has been exported without the extended
information. information.
This enables viewing and sorting by the latest child mtime, or modified time,
using 'm' and 'M', respectively.
=back =back
=head2 Interface options =head2 Interface options
@ -208,6 +211,11 @@ Order by number of items (press again for descending order)
Toggle between showing disk usage and showing apparent size. Toggle between showing disk usage and showing apparent size.
=item M
Order by latest child mtime, or modified time. (press again for descending order)
Requires the -e flag.
=item d =item d
Delete the selected file or directory. An error message will be shown when the Delete the selected file or directory. An error message will be shown when the
@ -228,6 +236,10 @@ the current directory.
Toggle display of child item counts. Toggle display of child item counts.
=item m
Toggle display of latest child mtime, or modified time. Requies the -e flag.
=item e =item e
Show/hide 'hidden' or 'excluded' files and directories. Please note that even Show/hide 'hidden' or 'excluded' files and directories. Please note that even

Просмотреть файл

@ -31,7 +31,7 @@
#include <time.h> #include <time.h>
static int graph = 1, show_as = 0, info_show = 0, info_page = 0, info_start = 0, show_items = 0; static int graph = 1, show_as = 0, info_show = 0, info_page = 0, info_start = 0, show_items = 0, show_mtime = 0;
static char *message = NULL; static char *message = NULL;
@ -196,6 +196,30 @@ static void browse_draw_items(struct dir *n, int *x) {
} }
static void browse_draw_mtime(struct dir *n, int *x) {
enum ui_coltype c = n->flags & FF_BSEL ? UIC_SEL : UIC_DEFAULT;
char mbuf[26];
struct dir_ext *e;
time_t t;
if (n->flags & FF_EXT) {
e = dir_ext_ptr(n);
} else if (!strcmp(n->name, "..") && (n->parent->flags & FF_EXT)) {
e = dir_ext_ptr(n->parent);
} else {
snprintf(mbuf, sizeof(mbuf), "no mtime");
goto no_mtime;
}
t = (time_t)e->mtime;
strftime(mbuf, sizeof(mbuf), "%Y-%m-%d %H:%M:%S %z", localtime(&t));
uic_set(c == UIC_SEL ? UIC_NUM_SEL : UIC_NUM);
no_mtime:
printw("%26s", mbuf);
*x += 27;
}
static void browse_draw_item(struct dir *n, int row) { static void browse_draw_item(struct dir *n, int row) {
int x = 0; int x = 0;
@ -218,6 +242,11 @@ static void browse_draw_item(struct dir *n, int row) {
browse_draw_items(n, &x); browse_draw_items(n, &x);
move(row, x); move(row, x);
if (extended_info && show_mtime) {
browse_draw_mtime(n, &x);
move(row, x);
}
if(n->flags & FF_DIR) if(n->flags & FF_DIR)
c = c == UIC_SEL ? UIC_DIR_SEL : UIC_DIR; c = c == UIC_SEL ? UIC_DIR_SEL : UIC_DIR;
addchc(c, n->flags & FF_DIR ? '/' : ' '); addchc(c, n->flags & FF_DIR ? '/' : ' ');
@ -409,6 +438,12 @@ int browse_key(int ch) {
dirlist_set_sort(DL_COL_ITEMS, dirlist_sort_col == DL_COL_ITEMS ? !dirlist_sort_desc : 1, DL_NOCHANGE); dirlist_set_sort(DL_COL_ITEMS, dirlist_sort_col == DL_COL_ITEMS ? !dirlist_sort_desc : 1, DL_NOCHANGE);
info_show = 0; info_show = 0;
break; break;
case 'M':
if (extended_info) {
dirlist_set_sort(DL_COL_MTIME, dirlist_sort_col == DL_COL_MTIME ? !dirlist_sort_desc : 1, DL_NOCHANGE);
info_show = 0;
}
break;
case 'e': case 'e':
dirlist_set_hidden(!dirlist_hidden); dirlist_set_hidden(!dirlist_hidden);
info_show = 0; info_show = 0;
@ -474,6 +509,10 @@ int browse_key(int ch) {
case 'c': case 'c':
show_items = !show_items; show_items = !show_items;
break; break;
case 'm':
if (extended_info)
show_mtime = !show_mtime;
break;
case 'i': case 'i':
info_show = !info_show; info_show = !info_show;
break; break;

Просмотреть файл

@ -144,10 +144,13 @@ static int item(struct dir *dir, const char *name, struct dir_ext *ext) {
* possible hard link, because hlnk_check() will take care of it in that * possible hard link, because hlnk_check() will take care of it in that
* case. */ * case. */
if(item->flags & FF_HLNKC) { if(item->flags & FF_HLNKC) {
addparentstats(item->parent, 0, 0, 1); addparentstats(item->parent, 0, 0, 0, 1);
hlink_check(item); hlink_check(item);
} else } else if(item->flags & FF_EXT) {
addparentstats(item->parent, item->size, item->asize, 1); addparentstats(item->parent, item->size, item->asize, dir_ext_ptr(item)->mtime, 1);
} else {
addparentstats(item->parent, item->size, item->asize, 0, 1);
}
/* propagate ERR and SERR back up to the root */ /* propagate ERR and SERR back up to the root */
if(item->flags & FF_SERR || item->flags & FF_ERR) if(item->flags & FF_SERR || item->flags & FF_ERR)

Просмотреть файл

@ -50,6 +50,14 @@ static struct dir *parent_alloc, *head, *head_real, *selected, *top = NULL;
)) ))
static inline int cmp_mtime(struct dir *x, struct dir*y) {
int64_t x_mtime = 0, y_mtime = 0;
if (x->flags & FF_EXT)
x_mtime = dir_ext_ptr(x)->mtime;
if (y->flags & FF_EXT)
y_mtime = dir_ext_ptr(y)->mtime;
return (x_mtime > y_mtime ? 1 : (x_mtime == y_mtime ? 0 : -1));
}
static int dirlist_cmp(struct dir *x, struct dir *y) { static int dirlist_cmp(struct dir *x, struct dir *y) {
int r; int r;
@ -80,7 +88,8 @@ static int dirlist_cmp(struct dir *x, struct dir *y) {
r = dirlist_sort_col == DL_COL_NAME ? CMP_NAME : r = dirlist_sort_col == DL_COL_NAME ? CMP_NAME :
dirlist_sort_col == DL_COL_SIZE ? CMP_SIZE : dirlist_sort_col == DL_COL_SIZE ? CMP_SIZE :
dirlist_sort_col == DL_COL_ASIZE ? CMP_ASIZE : dirlist_sort_col == DL_COL_ASIZE ? CMP_ASIZE :
CMP_ITEMS; dirlist_sort_col == DL_COL_ITEMS ? CMP_ITEMS :
cmp_mtime(x, y);
/* try 2 */ /* try 2 */
if(!r) if(!r)
r = dirlist_sort_col == DL_COL_SIZE ? CMP_ASIZE : CMP_SIZE; r = dirlist_sort_col == DL_COL_SIZE ? CMP_ASIZE : CMP_SIZE;

Просмотреть файл

@ -37,6 +37,7 @@
#define DL_COL_SIZE 1 #define DL_COL_SIZE 1
#define DL_COL_ASIZE 2 #define DL_COL_ASIZE 2
#define DL_COL_ITEMS 3 #define DL_COL_ITEMS 3
#define DL_COL_MTIME 4
void dirlist_open(struct dir *); void dirlist_open(struct dir *);

Просмотреть файл

@ -32,7 +32,7 @@
int page, start; int page, start;
#define KEYS 17 #define KEYS 19
char *keys[KEYS*2] = { char *keys[KEYS*2] = {
/*|----key----| |----------------description----------------|*/ /*|----key----| |----------------description----------------|*/
"up, k", "Move cursor up", "up, k", "Move cursor up",
@ -42,11 +42,13 @@ char *keys[KEYS*2] = {
"n", "Sort by name (ascending/descending)", "n", "Sort by name (ascending/descending)",
"s", "Sort by size (ascending/descending)", "s", "Sort by size (ascending/descending)",
"C", "Sort by items (ascending/descending)", "C", "Sort by items (ascending/descending)",
"M", "Sort by mtime (-e flag)",
"d", "Delete selected file or directory", "d", "Delete selected file or directory",
"t", "Toggle dirs before files when sorting", "t", "Toggle dirs before files when sorting",
"g", "Show percentage and/or graph", "g", "Show percentage and/or graph",
"a", "Toggle between apparent size and disk usage", "a", "Toggle between apparent size and disk usage",
"c", "Toggle display of child item counts", "c", "Toggle display of child item counts",
"m", "Toggle display of latest mtime (-e flag)",
"e", "Show/hide hidden or excluded files", "e", "Show/hide hidden or excluded files",
"i", "Show information about selected item", "i", "Show information about selected item",
"r", "Recalculate the current directory", "r", "Recalculate the current directory",

Просмотреть файл

@ -344,8 +344,11 @@ void freedir(struct dir *dr) {
freedir_hlnk(dr); freedir_hlnk(dr);
/* update sizes of parent directories if this isn't a hard link. /* update sizes of parent directories if this isn't a hard link.
* If this is a hard link, freedir_hlnk() would have done so already */ * If this is a hard link, freedir_hlnk() would have done so already
addparentstats(dr->parent, dr->flags & FF_HLNKC ? 0 : -dr->size, dr->flags & FF_HLNKC ? 0 : -dr->asize, -(dr->items+1)); *
* mtime is 0 here because recalculating the maximum at every parent
* dir is expensive, but might be good feature to add later if desired */
addparentstats(dr->parent, dr->flags & FF_HLNKC ? 0 : -dr->size, dr->flags & FF_HLNKC ? 0 : -dr->asize, 0, -(dr->items+1));
free(dr); free(dr);
} }
@ -397,11 +400,16 @@ struct dir *getroot(struct dir *d) {
} }
void addparentstats(struct dir *d, int64_t size, int64_t asize, int items) { void addparentstats(struct dir *d, int64_t size, int64_t asize, uint64_t mtime, int items) {
struct dir_ext *e;
while(d) { while(d) {
d->size = adds64(d->size, size); d->size = adds64(d->size, size);
d->asize = adds64(d->asize, asize); d->asize = adds64(d->asize, asize);
d->items += items; d->items += items;
if (d->flags & FF_EXT) {
e = dir_ext_ptr(d);
e->mtime = (e->mtime > mtime) ? e->mtime : mtime;
}
d = d->parent; d = d->parent;
} }
} }

Просмотреть файл

@ -163,7 +163,7 @@ struct dir *getroot(struct dir *);
: (a)+(b) < 0 ? 0 : (a)+(b)) : (a)+(b) < 0 ? 0 : (a)+(b))
/* Adds a value to the size, asize and items fields of *d and its parents */ /* Adds a value to the size, asize and items fields of *d and its parents */
void addparentstats(struct dir *, int64_t, int64_t, int); void addparentstats(struct dir *, int64_t, int64_t, uint64_t, int);
/* A simple stack implemented in macros */ /* A simple stack implemented in macros */