In fact, file copying doesn't ask overwrite confirmation...
This commit is contained in:
parent
8a0e74ee2d
commit
efcec445b7
|
@ -16,9 +16,9 @@ SYNOPSIS
|
|||
#include <libp7.h>
|
||||
|
||||
int p7_copyfile(char *dirname, char *filename, char *newdir, char *newname,
|
||||
char *devname, int overwrite, int (*ow_conf)(void));
|
||||
char *devname);
|
||||
|
||||
p7_copyfile("hidden", "file.txt", NULL, "VISIBLE.txt", "fls0", 1, NULL);
|
||||
p7_copyfile("hidden", "file.txt", NULL, "VISIBLE.txt", "fls0");
|
||||
----
|
||||
|
||||
DESCRIPTION
|
||||
|
@ -26,12 +26,6 @@ DESCRIPTION
|
|||
p7_copyfile copies a file to another on a distant device. A NULL directory
|
||||
name is interpreted as root directory.
|
||||
|
||||
In case the destination file exists on the calculator :
|
||||
|
||||
* if "ow_conf" is not NULL, the function will be called. If it returns 0, then
|
||||
the file is not overwritten, otherwise, it is.
|
||||
* if it is, then "overwrite" will be interpreted as the response of ow_conf.
|
||||
|
||||
SEE ALSO
|
||||
--------
|
||||
*libp7*(3),
|
||||
|
|
|
@ -83,6 +83,6 @@ int p7_delfile(char *dirname, char *filename, char *devname);
|
|||
|
||||
/* Copy file on distant device */
|
||||
int p7_copyfile(char *dirname, char *filename, char *newdir, char *newname,
|
||||
char *devname, int overwrite, int (*ow_conf)(void));
|
||||
char *devname);
|
||||
|
||||
#endif /* LIBP7_H */
|
||||
|
|
|
@ -23,8 +23,8 @@ int p7_send_cmdfls_reqfile(char *dirname, char *filename, char *devname);
|
|||
int p7_send_cmdfls_sendfile(p7_commandoverwrite_t ow, unsigned int fs,
|
||||
char *dirname, char *filename, char *devname);
|
||||
int p7_send_cmdfls_delfile(char *dirname, char *filename, char *devname);
|
||||
int p7_send_cmdfls_copyfile(p7_commandoverwrite_t ow, char *dirname,
|
||||
char *filename, char *newdir, char *newname, char *devname);
|
||||
int p7_send_cmdfls_copyfile(char *dirname, char *filename,
|
||||
char *newdir, char *newname, char *devname);
|
||||
|
||||
/* Data */
|
||||
int p7_send_data(unsigned int total, unsigned int id,
|
||||
|
|
|
@ -266,7 +266,6 @@ int p7_send_cmdfls_delfile(char *dirname, char *filename, char *devname)
|
|||
* p7_send_cmdfls_copyfile:
|
||||
* Copy a file.
|
||||
*
|
||||
* @arg ow the overwrite mode
|
||||
* @arg dirname the name of the directory
|
||||
* @arg filename the name of the file
|
||||
* @arg newdir the name of the new directory
|
||||
|
@ -275,10 +274,10 @@ int p7_send_cmdfls_delfile(char *dirname, char *filename, char *devname)
|
|||
* @return if it worked
|
||||
*/
|
||||
|
||||
int p7_send_cmdfls_copyfile(p7_commandoverwrite_t ow, char *dirname,
|
||||
char *filename, char *newdir, char *newname, char *devname)
|
||||
int p7_send_cmdfls_copyfile(char *dirname, char *filename, char *newdir,
|
||||
char *newname, char *devname)
|
||||
{
|
||||
/* send packet */
|
||||
return (p7_send_cmd_data(ST_FLS_CP, ow, 0, 0,
|
||||
return (p7_send_cmd_data(ST_FLS_CP, 0, 0, 0,
|
||||
dirname, filename, newdir, newname, devname, NULL));
|
||||
}
|
||||
|
|
|
@ -19,14 +19,11 @@
|
|||
* @arg newdir the new directory name
|
||||
* @arg newname the new filename
|
||||
* @arg devname the device name
|
||||
* @arg overwrite if no confirmated callback, should overwrite or not
|
||||
* @arg ow_conf if file exists and this callback is NULL,
|
||||
* call it. If answer is 1, overwrite, otherwise, not.
|
||||
* @return if it worked
|
||||
*/
|
||||
|
||||
int p7_copyfile(char *dirname, char *filename, char *newdir, char *newname,
|
||||
char *devname, int overwrite, int (*ow_conf)(void))
|
||||
char *devname)
|
||||
{
|
||||
/* check filenames */
|
||||
if (!p7_validate_filename(filename) || !p7_validate_filename(newname)) {
|
||||
|
@ -43,15 +40,9 @@ int p7_copyfile(char *dirname, char *filename, char *newdir, char *newname,
|
|||
return (0);
|
||||
}
|
||||
|
||||
/* choose overwrite mode */
|
||||
p7_commandoverwrite_t owmode;
|
||||
if (ow_conf || !overwrite)
|
||||
owmode = p7_cow_request_confirmation_before_overwriting;
|
||||
else owmode = p7_cow_force_overwrite;
|
||||
|
||||
/* send command packet */
|
||||
log_info("sending command");
|
||||
if (!p7_send_cmdfls_copyfile(owmode, dirname, filename, newdir,
|
||||
if (!p7_send_cmdfls_copyfile(dirname, filename, newdir,
|
||||
newname, devname)) {
|
||||
log_fatal("couldn't send command/get its response");
|
||||
return (0);
|
||||
|
@ -67,35 +58,6 @@ int p7_copyfile(char *dirname, char *filename, char *newdir, char *newname,
|
|||
/* - check it - */
|
||||
if (response.type == p7_pt_error) {
|
||||
switch (response.error.code) {
|
||||
/* file exists, confirm or not */
|
||||
case p7_ec_overwrite:
|
||||
log_info("calc wanted overwrite confirmation");
|
||||
/* check whether to ask */
|
||||
int denied = 0;
|
||||
if (ow_conf && (*ow_conf)()) {
|
||||
log_info("sending yes to overwrite confirmation");
|
||||
if (!p7_send_ack_confirm_ow())
|
||||
return (0);
|
||||
} else {
|
||||
log_info("sending no to overwrite confirmation");
|
||||
if (!p7_send_err_overwrite_no())
|
||||
return (0);
|
||||
denied = 1;
|
||||
p7_error = p7_error_denied_overwrite;
|
||||
}
|
||||
/* check if response packet is ack */
|
||||
if (response.type != p7_pt_ack) {
|
||||
p7_error = p7_error_unknown;
|
||||
log_info("response packet wasn't ack");
|
||||
return (0);
|
||||
}
|
||||
/* if we denied, stop here */
|
||||
if (denied) {
|
||||
p7_error = p7_error_denied_overwrite;
|
||||
return (0);
|
||||
}
|
||||
break;
|
||||
|
||||
/* overwrite impossible */
|
||||
case p7_ec_overwrite_noresponse:
|
||||
case p7_ec_overwrite_impossible:
|
||||
|
@ -110,7 +72,7 @@ int p7_copyfile(char *dirname, char *filename, char *newdir, char *newname,
|
|||
return (0);
|
||||
|
||||
/* resend error - just here to stfu the warning */
|
||||
case p7_ec_resend:
|
||||
default:
|
||||
p7_error = p7_error_unknown;
|
||||
return (0);
|
||||
}
|
||||
|
|
Reference in New Issue