b212b3d031
So propagator can download ISO from a directory with "many" [1] files and display a nice progress bar. [1] In fact 12 of them or so is enough. The `LIST` ftp command produces quite a lot of noise^W data. For instance, this single entry: -rw-r--r-- 1 ftp ftp 1862483968 Jul 28 00:23 alt-p10-gnome3-20210728-aarch64.iso takes 95 bytes, hence it takes only 21 files to overflow the fixed size 2000 bytes buffer, so `ftp_get_filesize` is unable to figure out the size of 22nd and subsequent files. Process the output of the `LIST` command line by line to avoid the problem. While at it avoid buffer underruns (i.e. when the server reply contains no whitespace at all).
61 lines
1.4 KiB
C
61 lines
1.4 KiB
C
#include <stdio.h>
|
|
#include "url.c" /* yes, include the **source** file */
|
|
#include "test_common.c" /* yes, include the **source** file */
|
|
|
|
static int
|
|
test_basename_dirname(const char *path,
|
|
const char *dir_expected,
|
|
const char *name_expected,
|
|
int shouldfail)
|
|
{
|
|
int ret = 0, err = 0;
|
|
char *dir = NULL, *name = NULL;
|
|
|
|
err = basename_dirname(path, &dir, &name);
|
|
if (!shouldfail) {
|
|
if (err < 0) {
|
|
log_message("%s: FAIL: path='%s'", __func__, path);
|
|
return 1;
|
|
}
|
|
if (strcmp(dir, dir_expected)) {
|
|
log_message("%s: FAIL: expected dir '%s' != actual '%s'",
|
|
__func__, dir_expected, dir);
|
|
ret += 1;
|
|
}
|
|
if (strcmp(name, name_expected)) {
|
|
log_message("%s: FAIL: expected name '%s' != actual '%s'",
|
|
__func__, name_expected, name);
|
|
ret += 1;
|
|
}
|
|
} else {
|
|
if (err == 0) {
|
|
log_message("%s: XPASS: path='%s'", __func__, path);
|
|
ret = 1;
|
|
}
|
|
}
|
|
if (!shouldfail && ret == 0) {
|
|
log_message("%s: PASS: path='%s', dir='%s', name='%s'",
|
|
__func__, path, dir, name);
|
|
}
|
|
if (shouldfail && err != 0) {
|
|
log_message("%s: XFAIL: path='%s'", __func__, path);
|
|
}
|
|
if (dir) {
|
|
free(dir);
|
|
}
|
|
if (name) {
|
|
free(name);
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
int main(int argc, char **argv) {
|
|
int errc = 0;
|
|
errc += test_basename_dirname("/abs/name", "/abs", "name", 0);
|
|
errc += test_basename_dirname("rel/name", "rel", "name", 0);
|
|
errc += test_basename_dirname("aaa", "", "", 1);
|
|
|
|
return errc;
|
|
}
|
|
|