From 555bfb581365efacec4c2a0c3d499a15ccd0f716 Mon Sep 17 00:00:00 2001 From: "Thomas \"Cakeisalie5\" Touhey" Date: Fri, 27 Jan 2017 22:34:14 +0100 Subject: [PATCH] Added auto-optimizing for sending, made delete -> del alias. --- src/p7/args.c | 2 +- src/p7/main.c | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/p7/args.c b/src/p7/args.c index 6d59d74..701fd3d 100644 --- a/src/p7/args.c +++ b/src/p7/args.c @@ -303,7 +303,7 @@ int parse_args(int ac, char **av, args_t *args) args->dirname = s_dir ? s_dir : NULL; args->newname = aav[2]; args->newdir = s_todir ? s_todir : NULL; - } else if (!strcmp(aav[0], "del")) { + } else if (!strcmp(aav[0], "del") || !strcmp(aav[0], "delete")) { sub_init(del, 1) /* get filename */ diff --git a/src/p7/main.c b/src/p7/main.c index 3765ff4..4440498 100644 --- a/src/p7/main.c +++ b/src/p7/main.c @@ -213,7 +213,26 @@ int main(int ac, char **av) /* Check according to menu */ switch (args.menu) { case mn_send: - err = p7_sendfile(handle, args.local, args.dirname, args.filename, + /* get file size */ + fseek(args.local, 0, SEEK_END); + size_t filesize = (p7uint_t)ftell(args.local); + rewind(args.local); + + /* get capacity */ + p7uint_t capacity; + err = p7_getcapacity(handle, args.storage, &capacity); + if (err) break; + + /* optimize if required */ + if (filesize > (size_t)capacity) { + printf("Not enough space on the device. Let's optimize!\n"); + err = p7_optimize(handle, args.storage); + if (err) break; + } + + /* send the file */ + err = p7_sendstream(handle, args.local, filesize, + args.dirname, args.filename, args.storage, 1, args.force ? NULL : &sendfile_confirm, args.nicedisp ? &sendfile_display : NULL); break;