Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/vmem_client_slash_ftp.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,15 @@ static int vmem_client_slash_upload(struct slash *slash)
unsigned int timeout = slash_dfl_timeout;
unsigned int version = 1;
unsigned int offset = 0;
int do_crc32 = 0;

optparse_t * parser = optparse_new("upload", "<file> <address>");
optparse_add_help(parser);
csh_add_node_option(parser, &node);
optparse_add_unsigned(parser, 't', "timeout", "NUM", 0, &timeout, "timeout (default = <env>)");
optparse_add_unsigned(parser, 'v', "version", "NUM", 0, &version, "version (default = 1)");
optparse_add_unsigned(parser, 'o', "offset", "NUM", 0, &offset, "byte offset in file (default = 0)");
optparse_add_set(parser, 'C', "crc32", 1, &do_crc32, "Compare CRC32 as an upload success criteria");

rdp_opt_add(parser);

Expand Down Expand Up @@ -301,6 +303,29 @@ static int vmem_client_slash_upload(struct slash *slash)
break;
}

if (do_crc32 && res == SLASH_SUCCESS) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of duplicating this piece of code, please see if you can re-format the code from vmem_client_slash_crc32(...) to enable re-use.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the only piece that meakes sense to reuse is:

if (crc_file == crc) {
	printf("\033[32m\n");
	printf("  Success\n");
	printf("\033[0m\n");
} else {
	printf("\033[31m\n");
	printf("  Failure: %"PRIX32" != %"PRIX32"\n", crc, crc_file);
	printf("\033[0m\n");
}

Is it worth making a standalone function for a print?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally yes, if the same print is performed from multiple places, but why not reuse the call to csp_crc32_memory and vmem_client_calc_crc32?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uint32_t crc = csp_crc32_memory((const uint8_t *)data, size);
uint32_t crc_node;
int res = vmem_client_calc_crc32(node, timeout, address, size, &crc_node, 1);
if (res >= 0) {
if (crc_node == crc) {
printf("\033[32m\n");
printf(" Success\n");
printf("\033[0m\n");
} else {
printf("\033[31m\n");
printf(" Failure: %"PRIX32" != %"PRIX32"\n", crc, crc_node);
printf("\033[0m\n");
res = SLASH_ENOSPC;
}
} else {
printf("\033[31m\n");
printf(" Communication failure: %"PRId32"\n", res);
printf("\033[0m\n");
res = SLASH_ENOSPC;
}
}

free(data);
optparse_del(parser);

Expand Down