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).
75 lines
1.9 KiB
C
75 lines
1.9 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_parse_ftp_filesize(const char *line, const char *name,
|
|
unsigned long size_expected, int shouldfail)
|
|
{
|
|
unsigned long size = 0;
|
|
int err = 0, ret = 0;
|
|
err = parse_ftp_filesize(line, name, &size);
|
|
if (shouldfail) {
|
|
if (err == 0) {
|
|
log_message("%s: XPASS: name='%s', line='%s'",
|
|
__func__, name, line);
|
|
ret += 1;
|
|
}
|
|
} else {
|
|
if (err != 0) {
|
|
log_message("%s: FAIL: name='%s', line='%s'", __func__, line, name);
|
|
ret += 1;
|
|
} else if (size != size_expected) {
|
|
log_message("%s: FAIL: size=%lu, expected=%lu, line='%s'",
|
|
__func__, size, size_expected, line);
|
|
ret += 1;
|
|
}
|
|
}
|
|
if (shouldfail && err != 0) {
|
|
log_message("%s: XFAIL: line='%s'", __func__, line);
|
|
}
|
|
if (!shouldfail && ret == 0) {
|
|
log_message("%s: PASS: size=%lu, line='%s'",
|
|
__func__, size_expected, line);
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
int main(int argc, char **argv) {
|
|
int err = 0;
|
|
err += test_parse_ftp_filesize(
|
|
"-rw-r--r-- 1 ftp ftp 3000000000 Apr 28 15:43 slinux-9.1-x86_64.iso",
|
|
"slinux-9.1-x86_64.iso",
|
|
3000000000UL,
|
|
0
|
|
);
|
|
err += test_parse_ftp_filesize(
|
|
"-rw-r--r-- 1 ftp ftp 123456789012345678901234567890 Apr 28 15:43 slinux-9.1-x86_64.iso",
|
|
"slinux-9.1-x86_64.iso",
|
|
ULONG_MAX, /* too big */
|
|
0);
|
|
|
|
/* invalid/unknown size is not an error with FTP */
|
|
err += test_parse_ftp_filesize("-rw-r--r-- 1 ftp ftp xyz Apr 28 15:43 slinux-9.1-x86_64.iso",
|
|
"slinux-9.1-x86_64.iso",
|
|
0,
|
|
0);
|
|
|
|
/* invalid/unknown size is not an error with FTP */
|
|
err += test_parse_ftp_filesize(
|
|
"??? slinux-9.1-x86_64.iso",
|
|
"slinux-9.1-x86_64.iso",
|
|
0,
|
|
0);
|
|
|
|
/* file name not in the reply */
|
|
err += test_parse_ftp_filesize(
|
|
"NOTFOUND",
|
|
"slinux-9.1-x86_64.iso",
|
|
0,
|
|
1
|
|
);
|
|
|
|
return err;
|
|
}
|