Introduction
Introduction Statistics Contact Development Disclaimer Help
Add patch to allow directory sort by date. - geomyidae - A small C-based gopher…
git clone git://bitreich.org/geomyidae/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfri…
Log
Files
Refs
Tags
README
LICENSE
---
commit c62c2fe3b1ab53fca1df7f14f6256c84c6276f73
parent 3401df4e6802a68dd34581ae0de6b7e34f45ea12
Author: Christoph Lohmann <[email protected]>
Date: Fri, 6 Aug 2021 22:48:20 +0200
Add patch to allow directory sort by date.
Thanks IanJ for sending it in!
Diffstat:
A patches/order-directories-by-date.… | 69 +++++++++++++++++++++++++++…
1 file changed, 69 insertions(+), 0 deletions(-)
---
diff --git a/patches/order-directories-by-date.patch b/patches/order-directorie…
@@ -0,0 +1,69 @@
+From 38a2a15d8b803ce5b725a6cb1f2b3ac75ab686c7 Mon Sep 17 00:00:00 2001
+From: root <[email protected]>
+Date: Fri, 6 Aug 2021 20:09:46 +0100
+Subject: [PATCH] Modification to allow directories to be ordered by date by
+ adding a file named .datesort to the directory.
+
+---
+ handlr.c | 38 +++++++++++++++++++++++++++++++++++++-
+ 1 file changed, 37 insertions(+), 1 deletion(-)
+
+diff --git a/handlr.c b/handlr.c
+index 0c230d3..e2e35a8 100644
+--- a/handlr.c
++++ b/handlr.c
+@@ -21,6 +21,33 @@
+ #include "ind.h"
+ #include "arg.h"
+
++char DIR_PATH[PATH_MAX];
++int datesort (const struct dirent **, const struct dirent **);
++
++int
++datesort(const struct dirent **a, const struct dirent **b)
++{
++ int rval;
++ struct stat sbuf1, sbuf2;
++ char path1[PATH_MAX], path2[PATH_MAX];
++
++ snprintf(path1, PATH_MAX, "%s/%s", DIR_PATH, (*a)->d_name);
++ snprintf(path2, PATH_MAX, "%s/%s", DIR_PATH, (*b)->d_name);
++
++ rval = stat(path1, &sbuf1);
++ if (rval) {
++ perror("stat");
++ return 0;
++ }
++ rval = stat(path2, &sbuf2);
++ if (rval) {
++ perror("stat");
++ return 0;
++ }
++
++ return sbuf1.st_mtime < sbuf2.st_mtime;
++}
++
+ void
+ handledir(int sock, char *path, char *port, char *base, char *args,
+ char *sear, char *ohost, char *chost, int istls)
+@@ -48,7 +75,16 @@ handledir(int sock, char *path, char *port, char *base, cha…
+ }
+ free(par);
+
+- ndir = scandir(pa[0] ? pa : ".", &dirent, 0, alphasort);
++ strcpy(DIR_PATH, pa);
++
++ char ds[PATH_MAX];
++ strcpy(ds, pa);
++ strcat(ds, "/.datesort");
++
++ int (*sortorder) (const struct dirent **, const struct dirent **) =\
++ (access(ds, F_OK) != -1) ? datesort : alphasort;
++
++ ndir = scandir(pa[0] ? pa : ".", &dirent, 0, sortorder);
+ if (ndir < 0) {
+ perror("scandir");
+ free(pa);
+--
+2.20.1
+
You are viewing proxied material from bitreich.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.