1.1 --- a/libfsclient/lib/src/file.cc Fri Jan 14 01:10:35 2022 +0100
1.2 +++ b/libfsclient/lib/src/file.cc Thu Jan 27 23:45:17 2022 +0100
1.3 @@ -1,7 +1,7 @@
1.4 /*
1.5 * File access convenience functions.
1.6 *
1.7 - * Copyright (C) 2021 Paul Boddie <paul@boddie.org.uk>
1.8 + * Copyright (C) 2021, 2022 Paul Boddie <paul@boddie.org.uk>
1.9 *
1.10 * This program is free software; you can redistribute it and/or
1.11 * modify it under the terms of the GNU General Public License as
1.12 @@ -155,7 +155,35 @@
1.13 err = file_context_remove(&context);
1.14
1.15 /* Close the context, although a separate mechanism could permit contexts to
1.16 - open several files. */
1.17 + remove several files. */
1.18 +
1.19 + file_close(&context);
1.20 + return err;
1.21 +}
1.22 +
1.23 +/* Rename an object in the filesystem. This is a convenience function invoking
1.24 + file_context and file_context_rename. */
1.25 +
1.26 +long file_rename(const char *source, const char *target, l4_cap_idx_t server)
1.27 +{
1.28 + file_t context;
1.29 + offset_t written;
1.30 + long err;
1.31 +
1.32 + err = file_context(&context, server);
1.33 + if (err)
1.34 + return err;
1.35 +
1.36 + if (!file_string_set(&context, source, 0, &written))
1.37 + return -L4_ENOMEM;
1.38 +
1.39 + if (!file_string_set(&context, target, written + 1, NULL))
1.40 + return -L4_ENOMEM;
1.41 +
1.42 + err = file_context_rename(&context);
1.43 +
1.44 + /* Close the context, although a separate mechanism could permit contexts to
1.45 + rename several files. */
1.46
1.47 file_close(&context);
1.48 return err;
1.49 @@ -211,6 +239,14 @@
1.50 return openercontext.remove();
1.51 }
1.52
1.53 +/* Rename a file using the given context. */
1.54 +
1.55 +long file_context_rename(file_t *context)
1.56 +{
1.57 + client_OpenerContext openercontext(context->ref);
1.58 + return openercontext.rename();
1.59 +}
1.60 +
1.61
1.62
1.63 /* Flush populated data and obtain an updated file size and populated data