mirror of
https://github.com/wiiu-env/ftpiiu_plugin.git
synced 2024-11-17 18:29:19 +01:00
implement RNFR and RNTO
This commit is contained in:
parent
020f4c21df
commit
c4f5435936
66
source/ftp.c
66
source/ftp.c
@ -968,7 +968,12 @@ ftp_session_read_command(ftp_session_t *session)
|
|||||||
key.name, args);
|
key.name, args);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
/* clear RENAME flag for all commands except RNTO */
|
||||||
|
if(strcasecmp(command->name, "RNTO") != 0)
|
||||||
|
session->flags &= ~SESSION_RENAME;
|
||||||
command->handler(session, args);
|
command->handler(session, args);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2048,24 +2053,55 @@ FTP_DECLARE(RMD)
|
|||||||
|
|
||||||
FTP_DECLARE(RNFR)
|
FTP_DECLARE(RNFR)
|
||||||
{
|
{
|
||||||
|
#ifdef _3DS
|
||||||
|
Result ret;
|
||||||
|
Handle fd;
|
||||||
|
#else
|
||||||
|
int rc;
|
||||||
|
struct stat st;
|
||||||
|
#endif
|
||||||
console_print("%s %s\n", __func__, args ? args : "");
|
console_print("%s %s\n", __func__, args ? args : "");
|
||||||
|
|
||||||
ftp_session_set_state(session, COMMAND_STATE);
|
ftp_session_set_state(session, COMMAND_STATE);
|
||||||
|
|
||||||
session->flags &= ~SESSION_RENAME;
|
|
||||||
|
|
||||||
if(validate_path(args) != 0)
|
if(validate_path(args) != 0)
|
||||||
return ftp_send_response(session, 553, "invalid file name\r\n");
|
return ftp_send_response(session, 553, "invalid file name\r\n");
|
||||||
|
|
||||||
build_path(session, args);
|
build_path(session, args);
|
||||||
|
|
||||||
|
#ifdef _3DS
|
||||||
|
ret = FSUSER_OpenFile(NULL, &fd, sdmcArchive,
|
||||||
|
FS_makePath(PATH_CHAR, session->buffer),
|
||||||
|
FS_OPEN_READ, FS_ATTRIBUTE_NONE);
|
||||||
|
if(ret != 0)
|
||||||
|
ret = FSUSER_OpenDirectory(NULL, &fd, sdmcArchive,
|
||||||
|
FS_makePath(PATH_CHAR, session->buffer));
|
||||||
|
if(ret != 0)
|
||||||
|
{
|
||||||
|
console_print("no such file or directory\n");
|
||||||
|
return ftp_send_response(session, 450, "no such file or directory\r\n");
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
rc = lstat(session->buffer, &st);
|
||||||
|
if(rc != 0)
|
||||||
|
{
|
||||||
|
console_print("lstat: %s\n", strerror(errno));
|
||||||
|
return ftp_send_response(session, 450, "no such file or directory\r\n");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
session->flags |= SESSION_RENAME;
|
session->flags |= SESSION_RENAME;
|
||||||
|
|
||||||
return ftp_send_response(session, 200, "OK\r\n");
|
return ftp_send_response(session, 350, "OK\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
FTP_DECLARE(RNTO)
|
FTP_DECLARE(RNTO)
|
||||||
{
|
{
|
||||||
|
#ifdef _3DS
|
||||||
|
Result ret;
|
||||||
|
#else
|
||||||
|
int rc;
|
||||||
|
#endif
|
||||||
char buffer[1024];
|
char buffer[1024];
|
||||||
|
|
||||||
console_print("%s %s\n", __func__, args ? args : "");
|
console_print("%s %s\n", __func__, args ? args : "");
|
||||||
@ -2084,8 +2120,28 @@ FTP_DECLARE(RNTO)
|
|||||||
|
|
||||||
build_path(session, args);
|
build_path(session, args);
|
||||||
|
|
||||||
/* TODO perform rename(buffer, session->buffer) */
|
#ifdef _3DS
|
||||||
return ftp_send_response(session, 502, "unavailable\r\n");
|
ret = FSUSER_RenameFile(NULL,
|
||||||
|
sdmcArchive, FS_makePath(PATH_CHAR, buffer),
|
||||||
|
sdmcArchive, FS_makePath(PATH_CHAR, session->buffer));
|
||||||
|
if(ret != 0)
|
||||||
|
ret = FSUSER_RenameDirectory(NULL,
|
||||||
|
sdmcArchive, FS_makePath(PATH_CHAR, buffer),
|
||||||
|
sdmcArchive, FS_makePath(PATH_CHAR, session->buffer));
|
||||||
|
if(ret != 0)
|
||||||
|
{
|
||||||
|
console_print("FSUSER_RenameFile/Directory: 0x%08X\n", (unsigned int)ret);
|
||||||
|
return ftp_send_response(session, 550, "failed to rename file/directory\r\n");
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
rc = rename(buffer, session->buffer);
|
||||||
|
{
|
||||||
|
console_print("rename: %s\n", strerror(errno));
|
||||||
|
return ftp_send_response(session, 550, "failed to rename file/directory\r\n");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return ftp_send_response(session, 250, "OK\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
FTP_DECLARE(STOR)
|
FTP_DECLARE(STOR)
|
||||||
|
Loading…
Reference in New Issue
Block a user