74 lines
2.3 KiB
C
74 lines
2.3 KiB
C
/* *****************************************************************************
|
|
* 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/>.
|
|
* ************************************************************************** */
|
|
#include <libp7/internals.h>
|
|
|
|
/**
|
|
* p7_delete:
|
|
* Deletes a distant file.
|
|
*
|
|
* @arg handle the libp7 handle
|
|
* @arg dirname the directory name
|
|
* @arg filename the file name
|
|
* @arg devname the device name
|
|
* @return if it worked
|
|
*/
|
|
|
|
p7_define_ufunc(p7_delete, p7_attrs_delete,
|
|
p7_handle_t *handle, const char *dirname,
|
|
const char *filename, const char *devname)
|
|
{
|
|
int err;
|
|
|
|
/* if no filename, put the directory name in the filename. */
|
|
if (!filename) { filename = dirname; dirname = NULL; }
|
|
|
|
/* make checks */
|
|
chk_handle(handle);
|
|
chk_seven(handle);
|
|
chk_active(handle);
|
|
chk_filename(filename);
|
|
chk_dirname(dirname);
|
|
|
|
/* send command packet */
|
|
log_info("sending command");
|
|
if ((err = p7_seven_send_cmdfls_delfile(handle,
|
|
dirname, filename, devname))) {
|
|
log_fatal("couldn't send command/get its response");
|
|
return (err);
|
|
} else if (response.p7_seven_packet_type != p7_seven_type_ack
|
|
&& response.p7_seven_packet_type != p7_seven_type_error) {
|
|
log_fatal("received an invalid answer");
|
|
return (p7_error_unknown);
|
|
}
|
|
|
|
/* - check error - */
|
|
if (response.p7_seven_packet_type == p7_seven_type_error)
|
|
switch (response.p7_seven_packet_code) {
|
|
case p7_seven_err_other:
|
|
log_fatal("file not found");
|
|
return (p7_error_notfound);
|
|
default:
|
|
log_fatal("unknown error");
|
|
return (p7_error_unknown);
|
|
}
|
|
|
|
/* we're done */
|
|
return (0);
|
|
}
|