From 4a9f1c098cdc0e96ceac5bc3bbf6566cad32d7bd Mon Sep 17 00:00:00 2001 From: Martin Szulecki Date: Thu, 2 Oct 2014 16:15:48 +0200 Subject: afc: Implement afc_remove_path_and_contents() for recursive deletion Only available on iOS 6 and later. --- include/libimobiledevice/afc.h | 12 ++++++++++++ src/afc.c | 24 ++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/include/libimobiledevice/afc.h b/include/libimobiledevice/afc.h index 667fd63..b045554 100644 --- a/include/libimobiledevice/afc.h +++ b/include/libimobiledevice/afc.h @@ -338,6 +338,18 @@ afc_error_t afc_make_link(afc_client_t client, afc_link_type_t linktype, const c */ afc_error_t afc_set_file_time(afc_client_t client, const char *path, uint64_t mtime); +/** + * Deletes a file or directory including possible contents. + * + * @param client The client to use. + * @param path The path to delete. (must be a fully-qualified path) + * @since libimobiledevice 1.1.7 + * @note Only available in iOS 6 and later. + * + * @return AFC_E_SUCCESS on success or an AFC_E_* error value. + */ +afc_error_t afc_remove_path_and_contents(afc_client_t client, const char *path); + /* Helper functions */ /** diff --git a/src/afc.c b/src/afc.c index 50ac5bf..2e2d62c 100644 --- a/src/afc.c +++ b/src/afc.c @@ -998,6 +998,30 @@ afc_error_t afc_set_file_time(afc_client_t client, const char *path, uint64_t mt return ret; } +afc_error_t afc_remove_path_and_contents(afc_client_t client, const char *path) +{ + uint32_t bytes = 0; + afc_error_t ret = AFC_E_UNKNOWN_ERROR; + + if (!client || !path || !client->afc_packet || !client->parent) + return AFC_E_INVALID_ARG; + + afc_lock(client); + + /* Send command */ + ret = afc_dispatch_packet(client, AFC_OP_REMOVE_PATH_AND_CONTENTS, path, strlen(path)+1, NULL, 0, &bytes); + if (ret != AFC_E_SUCCESS) { + afc_unlock(client); + return AFC_E_NOT_ENOUGH_DATA; + } + /* Receive response */ + ret = afc_receive_data(client, NULL, &bytes); + + afc_unlock(client); + + return ret; +} + afc_error_t afc_dictionary_free(char **dictionary) { int i = 0; -- cgit v1.1-32-gdbae