mirror of
https://github.com/cesanta/mongoose.git
synced 2026-11-21 19:51:50 +00:00
Fix #1396 - JS sorting code for dir listing
This commit is contained in:
1 parent
12fe66370f
commit
3d78b14deb
2 files changed
+14
-12
No files matched your search
+7
-6
@@ -1322,20 +1322,21 @@ static void printdirentry(const char *name, void *userdata) {
|
|||||||
struct printdirentrydata *d = (struct printdirentrydata *) userdata;
|
struct printdirentrydata *d = (struct printdirentrydata *) userdata;
|
||||||
struct mg_fs *fs = d->opts->fs == NULL ? &mg_fs_posix : d->opts->fs;
|
struct mg_fs *fs = d->opts->fs == NULL ? &mg_fs_posix : d->opts->fs;
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
time_t mtime = 0;
|
time_t t = 0;
|
||||||
char path[MG_PATH_MAX], sz[64], mod[64];
|
char path[MG_PATH_MAX], sz[64], mod[64];
|
||||||
int flags, n = 0;
|
int flags, n = 0;
|
||||||
|
|
||||||
// LOG(LL_DEBUG, ("[%s] [%s]", d->dir, name));
|
// LOG(LL_DEBUG, ("[%s] [%s]", d->dir, name));
|
||||||
if (snprintf(path, sizeof(path), "%s%c%s", d->dir, '/', name) < 0) {
|
if (snprintf(path, sizeof(path), "%s%c%s", d->dir, '/', name) < 0) {
|
||||||
LOG(LL_ERROR, ("%s truncated", name));
|
LOG(LL_ERROR, ("%s truncated", name));
|
||||||
} else if ((flags = fs->stat(path, &size, &mtime)) == 0) {
|
} else if ((flags = fs->stat(path, &size, &t)) == 0) {
|
||||||
LOG(LL_ERROR, ("%lu stat(%s): %d", d->c->id, path, errno));
|
LOG(LL_ERROR, ("%lu stat(%s): %d", d->c->id, path, errno));
|
||||||
} else {
|
} else {
|
||||||
const char *slash = flags & MG_FS_DIR ? "/" : "";
|
const char *slash = flags & MG_FS_DIR ? "/" : "";
|
||||||
struct tm t;
|
struct tm tm;
|
||||||
if (flags & MG_FS_DIR) {
|
if (flags & MG_FS_DIR) {
|
||||||
snprintf(sz, sizeof(sz), "%s", "[DIR]");
|
snprintf(sz, sizeof(sz), "%s", "[DIR]");
|
||||||
|
size = -1;
|
||||||
} else if (size < 1024) {
|
} else if (size < 1024) {
|
||||||
snprintf(sz, sizeof(sz), "%d", (int) size);
|
snprintf(sz, sizeof(sz), "%d", (int) size);
|
||||||
} else if (size < 0x100000) {
|
} else if (size < 0x100000) {
|
||||||
@@ -1345,12 +1346,12 @@ static void printdirentry(const char *name, void *userdata) {
|
|||||||
} else {
|
} else {
|
||||||
snprintf(sz, sizeof(sz), "%.1fG", (double) size / 1073741824);
|
snprintf(sz, sizeof(sz), "%.1fG", (double) size / 1073741824);
|
||||||
}
|
}
|
||||||
strftime(mod, sizeof(mod), "%d-%b-%Y %H:%M", localtime_r(&mtime, &t));
|
strftime(mod, sizeof(mod), "%d-%b-%Y %H:%M", localtime_r(&t, &tm));
|
||||||
n = (int) mg_url_encode(name, strlen(name), path, sizeof(path));
|
n = (int) mg_url_encode(name, strlen(name), path, sizeof(path));
|
||||||
mg_printf(d->c,
|
mg_printf(d->c,
|
||||||
" <tr><td><a href=\"%.*s%s\">%s%s</a></td>"
|
" <tr><td><a href=\"%.*s%s\">%s%s</a></td>"
|
||||||
"<td>%s</td><td>%s</td></tr>\n",
|
"<td name=%lu>%s</td><td name=" MG_INT64_FMT ">%s</td></tr>\n",
|
||||||
n, path, slash, name, slash, mod, sz);
|
n, path, slash, name, slash, (unsigned long) t, mod, size, sz);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+7
-6
@@ -573,20 +573,21 @@ static void printdirentry(const char *name, void *userdata) {
|
|||||||
struct printdirentrydata *d = (struct printdirentrydata *) userdata;
|
struct printdirentrydata *d = (struct printdirentrydata *) userdata;
|
||||||
struct mg_fs *fs = d->opts->fs == NULL ? &mg_fs_posix : d->opts->fs;
|
struct mg_fs *fs = d->opts->fs == NULL ? &mg_fs_posix : d->opts->fs;
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
time_t mtime = 0;
|
time_t t = 0;
|
||||||
char path[MG_PATH_MAX], sz[64], mod[64];
|
char path[MG_PATH_MAX], sz[64], mod[64];
|
||||||
int flags, n = 0;
|
int flags, n = 0;
|
||||||
|
|
||||||
// LOG(LL_DEBUG, ("[%s] [%s]", d->dir, name));
|
// LOG(LL_DEBUG, ("[%s] [%s]", d->dir, name));
|
||||||
if (snprintf(path, sizeof(path), "%s%c%s", d->dir, '/', name) < 0) {
|
if (snprintf(path, sizeof(path), "%s%c%s", d->dir, '/', name) < 0) {
|
||||||
LOG(LL_ERROR, ("%s truncated", name));
|
LOG(LL_ERROR, ("%s truncated", name));
|
||||||
} else if ((flags = fs->stat(path, &size, &mtime)) == 0) {
|
} else if ((flags = fs->stat(path, &size, &t)) == 0) {
|
||||||
LOG(LL_ERROR, ("%lu stat(%s): %d", d->c->id, path, errno));
|
LOG(LL_ERROR, ("%lu stat(%s): %d", d->c->id, path, errno));
|
||||||
} else {
|
} else {
|
||||||
const char *slash = flags & MG_FS_DIR ? "/" : "";
|
const char *slash = flags & MG_FS_DIR ? "/" : "";
|
||||||
struct tm t;
|
struct tm tm;
|
||||||
if (flags & MG_FS_DIR) {
|
if (flags & MG_FS_DIR) {
|
||||||
snprintf(sz, sizeof(sz), "%s", "[DIR]");
|
snprintf(sz, sizeof(sz), "%s", "[DIR]");
|
||||||
|
size = -1;
|
||||||
} else if (size < 1024) {
|
} else if (size < 1024) {
|
||||||
snprintf(sz, sizeof(sz), "%d", (int) size);
|
snprintf(sz, sizeof(sz), "%d", (int) size);
|
||||||
} else if (size < 0x100000) {
|
} else if (size < 0x100000) {
|
||||||
@@ -596,12 +597,12 @@ static void printdirentry(const char *name, void *userdata) {
|
|||||||
} else {
|
} else {
|
||||||
snprintf(sz, sizeof(sz), "%.1fG", (double) size / 1073741824);
|
snprintf(sz, sizeof(sz), "%.1fG", (double) size / 1073741824);
|
||||||
}
|
}
|
||||||
strftime(mod, sizeof(mod), "%d-%b-%Y %H:%M", localtime_r(&mtime, &t));
|
strftime(mod, sizeof(mod), "%d-%b-%Y %H:%M", localtime_r(&t, &tm));
|
||||||
n = (int) mg_url_encode(name, strlen(name), path, sizeof(path));
|
n = (int) mg_url_encode(name, strlen(name), path, sizeof(path));
|
||||||
mg_printf(d->c,
|
mg_printf(d->c,
|
||||||
" <tr><td><a href=\"%.*s%s\">%s%s</a></td>"
|
" <tr><td><a href=\"%.*s%s\">%s%s</a></td>"
|
||||||
"<td>%s</td><td>%s</td></tr>\n",
|
"<td name=%lu>%s</td><td name=" MG_INT64_FMT ">%s</td></tr>\n",
|
||||||
n, path, slash, name, slash, mod, sz);
|
n, path, slash, name, slash, (unsigned long) t, mod, size, sz);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user