mirror of https://github.com/ArduPilot/ardupilot
AP_Filesystem: support file rename
This commit is contained in:
parent
a021489580
commit
cf79843661
|
@ -182,6 +182,12 @@ int AP_Filesystem::mkdir(const char *pathname)
|
||||||
return backend.fs.mkdir(pathname);
|
return backend.fs.mkdir(pathname);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int AP_Filesystem::rename(const char *oldpath, const char *newpath)
|
||||||
|
{
|
||||||
|
const Backend &backend = backend_by_path(oldpath);
|
||||||
|
return backend.fs.rename(oldpath, newpath);
|
||||||
|
}
|
||||||
|
|
||||||
AP_Filesystem::DirHandle *AP_Filesystem::opendir(const char *pathname)
|
AP_Filesystem::DirHandle *AP_Filesystem::opendir(const char *pathname)
|
||||||
{
|
{
|
||||||
const Backend &backend = backend_by_path(pathname);
|
const Backend &backend = backend_by_path(pathname);
|
||||||
|
|
|
@ -93,6 +93,7 @@ public:
|
||||||
int stat(const char *pathname, struct stat *stbuf);
|
int stat(const char *pathname, struct stat *stbuf);
|
||||||
int unlink(const char *pathname);
|
int unlink(const char *pathname);
|
||||||
int mkdir(const char *pathname);
|
int mkdir(const char *pathname);
|
||||||
|
int rename(const char *oldpath, const char *newpath);
|
||||||
|
|
||||||
DirHandle *opendir(const char *pathname);
|
DirHandle *opendir(const char *pathname);
|
||||||
struct dirent *readdir(DirHandle *dirp);
|
struct dirent *readdir(DirHandle *dirp);
|
||||||
|
|
|
@ -91,6 +91,14 @@ int AP_Filesystem_ESP32::unlink(const char *pathname)
|
||||||
return ::unlink(pathname);
|
return ::unlink(pathname);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int AP_Filesystem_ESP32::rename(const char *oldpath, const char *newpath)
|
||||||
|
{
|
||||||
|
#if FSDEBUG
|
||||||
|
printf("DO rename %s \n", oldpath, newpath);
|
||||||
|
#endif
|
||||||
|
return ::rename(oldpath, newpath);
|
||||||
|
}
|
||||||
|
|
||||||
int AP_Filesystem_ESP32::mkdir(const char *pathname)
|
int AP_Filesystem_ESP32::mkdir(const char *pathname)
|
||||||
{
|
{
|
||||||
#if FSDEBUG
|
#if FSDEBUG
|
||||||
|
|
|
@ -33,6 +33,7 @@ public:
|
||||||
void *opendir(const char *pathname) override;
|
void *opendir(const char *pathname) override;
|
||||||
struct dirent *readdir(void *dirp) override;
|
struct dirent *readdir(void *dirp) override;
|
||||||
int closedir(void *dirp) override;
|
int closedir(void *dirp) override;
|
||||||
|
int rename(const char *oldpath, const char *newpath) override;
|
||||||
|
|
||||||
// return free disk space in bytes, -1 on error
|
// return free disk space in bytes, -1 on error
|
||||||
int64_t disk_free(const char *path) override;
|
int64_t disk_free(const char *path) override;
|
||||||
|
|
|
@ -665,6 +665,22 @@ int AP_Filesystem_FATFS::mkdir(const char *pathname)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int AP_Filesystem_FATFS::rename(const char *oldpath, const char *newpath)
|
||||||
|
{
|
||||||
|
FS_CHECK_ALLOWED(-1);
|
||||||
|
WITH_SEMAPHORE(sem);
|
||||||
|
|
||||||
|
errno = 0;
|
||||||
|
|
||||||
|
int res = f_rename(oldpath, newpath);
|
||||||
|
if (res != FR_OK) {
|
||||||
|
errno = fatfs_to_errno((FRESULT)res);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
wrapper structure to associate a dirent with a DIR
|
wrapper structure to associate a dirent with a DIR
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -30,6 +30,7 @@ public:
|
||||||
int unlink(const char *pathname) override;
|
int unlink(const char *pathname) override;
|
||||||
int mkdir(const char *pathname) override;
|
int mkdir(const char *pathname) override;
|
||||||
void *opendir(const char *pathname) override;
|
void *opendir(const char *pathname) override;
|
||||||
|
int rename(const char *oldpath, const char *newpath) override;
|
||||||
struct dirent *readdir(void *dirp) override;
|
struct dirent *readdir(void *dirp) override;
|
||||||
int closedir(void *dirp) override;
|
int closedir(void *dirp) override;
|
||||||
|
|
||||||
|
|
|
@ -57,6 +57,7 @@ public:
|
||||||
virtual void *opendir(const char *pathname) { return nullptr; }
|
virtual void *opendir(const char *pathname) { return nullptr; }
|
||||||
virtual struct dirent *readdir(void *dirp) { return nullptr; }
|
virtual struct dirent *readdir(void *dirp) { return nullptr; }
|
||||||
virtual int closedir(void *dirp) { return -1; }
|
virtual int closedir(void *dirp) { return -1; }
|
||||||
|
virtual int rename(const char *oldpath, const char *newpath) { return -1; }
|
||||||
|
|
||||||
// return free disk space in bytes, -1 on error
|
// return free disk space in bytes, -1 on error
|
||||||
virtual int64_t disk_free(const char *path) { return 0; }
|
virtual int64_t disk_free(const char *path) { return 0; }
|
||||||
|
|
|
@ -135,6 +135,14 @@ int AP_Filesystem_Posix::closedir(void *dirp)
|
||||||
return ::closedir((DIR *)dirp);
|
return ::closedir((DIR *)dirp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int AP_Filesystem_Posix::rename(const char *oldpath, const char *newpath)
|
||||||
|
{
|
||||||
|
FS_CHECK_ALLOWED(-1);
|
||||||
|
oldpath = map_filename(oldpath);
|
||||||
|
newpath = map_filename(newpath);
|
||||||
|
return ::rename(oldpath, newpath);
|
||||||
|
}
|
||||||
|
|
||||||
// return free disk space in bytes
|
// return free disk space in bytes
|
||||||
int64_t AP_Filesystem_Posix::disk_free(const char *path)
|
int64_t AP_Filesystem_Posix::disk_free(const char *path)
|
||||||
{
|
{
|
||||||
|
|
|
@ -41,6 +41,7 @@ public:
|
||||||
void *opendir(const char *pathname) override;
|
void *opendir(const char *pathname) override;
|
||||||
struct dirent *readdir(void *dirp) override;
|
struct dirent *readdir(void *dirp) override;
|
||||||
int closedir(void *dirp) override;
|
int closedir(void *dirp) override;
|
||||||
|
int rename(const char *oldpath, const char *newpath) override;
|
||||||
|
|
||||||
// return free disk space in bytes, -1 on error
|
// return free disk space in bytes, -1 on error
|
||||||
int64_t disk_free(const char *path) override;
|
int64_t disk_free(const char *path) override;
|
||||||
|
|
Loading…
Reference in New Issue