cake
/
libp7
Archived
1
0
Fork 1
This repository has been archived on 2024-03-16. You can view files and clone it, but cannot push or open issues or pull requests.
libp7/src/usage/storage/delete.c

70 lines
2.2 KiB
C
Raw Normal View History

/* *****************************************************************************
* usage/storage/delete.c -- delete a file/directory on the calculator.
* Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
*
* This file is part of libp7.
* libp7 is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 3.0 of the License,
* or (at your option) any later version.
*
* libp7 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with libp7; if not, see <http://www.gnu.org/licenses/>.
* ************************************************************************** */
2016-08-22 16:37:26 +02:00
#include <libp7/internals.h>
/**
2017-02-05 20:12:25 +01:00
* p7_delete:
2016-08-22 16:37:26 +02:00
* Deletes a distant file.
*
2016-09-25 22:01:42 +02:00
* @arg handle the libp7 handle
2016-08-22 16:37:26 +02:00
* @arg dirname the directory name
* @arg filename the file name
* @arg devname the device name
* @return if it worked
*/
2017-02-05 20:12:25 +01:00
int p7_delete(p7_handle_t *handle,
2016-10-05 22:31:01 +02:00
const char *dirname, const char *filename, const char *devname)
2016-08-22 16:37:26 +02:00
{
2016-09-25 22:01:42 +02:00
int err;
/* if no filename, put the directory name in the filename. */
if (!filename) { filename = dirname; dirname = NULL; }
2016-10-09 16:26:04 +02:00
/* make checks */
chk_handle(handle);
chk_active(handle);
2017-01-27 15:20:41 +01:00
chk_filename(filename);
chk_dirname(dirname);
2016-08-22 16:37:26 +02:00
/* send command packet */
2016-08-24 16:08:47 +02:00
log_info("sending command");
2016-09-25 22:01:42 +02:00
if ((err = p7_send_cmdfls_delfile(handle,
dirname, filename, devname))) {
2016-08-24 16:08:47 +02:00
log_fatal("couldn't send command/get its response");
2016-09-25 22:01:42 +02:00
return (err);
2016-10-09 16:26:04 +02:00
} else if (response.type != p7_pt_ack && response.type != p7_pt_error) {
2016-08-23 14:06:37 +02:00
log_fatal("received an invalid answer");
2016-09-25 22:01:42 +02:00
return (p7_error_unknown);
2016-08-22 16:37:26 +02:00
}
2016-10-09 16:26:04 +02:00
/* - check error - */
2017-01-04 13:38:20 +01:00
if (response.type == p7_pt_error) switch (response.code) {
case p7_err_other:
log_fatal("file not found");
2016-09-25 22:01:42 +02:00
return (p7_error_notfound);
default:
log_fatal("unknown error");
2016-09-25 22:01:42 +02:00
return (p7_error_unknown);
2016-08-22 16:37:26 +02:00
}
/* we're done */
2016-09-25 22:01:42 +02:00
return (0);
2016-08-22 16:37:26 +02:00
}