diff options
author | Vladimir Ermakov <vooon341@gmail.com> | 2014-09-22 13:48:43 +0400 |
---|---|---|
committer | Vladimir Ermakov <vooon341@gmail.com> | 2014-09-22 13:48:43 +0400 |
commit | 8eb310061693c86a9c8b3c7f6e2bab1ec680c46a (patch) | |
tree | b012c56604f7e66544d2806b80bfc94443f6436b /src | |
parent | 407a4e0f0675f0b283eea0632208c8c3f8b9ca20 (diff) | |
download | px4-firmware-8eb310061693c86a9c8b3c7f6e2bab1ec680c46a.tar.gz px4-firmware-8eb310061693c86a9c8b3c7f6e2bab1ec680c46a.tar.bz2 px4-firmware-8eb310061693c86a9c8b3c7f6e2bab1ec680c46a.zip |
FTP: Rename command.
Payload: `<oldpath>\0<newpath>`
See: man 2 rename
Diffstat (limited to 'src')
-rw-r--r-- | src/modules/mavlink/mavlink_ftp.cpp | 31 | ||||
-rw-r--r-- | src/modules/mavlink/mavlink_ftp.h | 2 |
2 files changed, 33 insertions, 0 deletions
diff --git a/src/modules/mavlink/mavlink_ftp.cpp b/src/modules/mavlink/mavlink_ftp.cpp index 14a42ed72..117cc4ec1 100644 --- a/src/modules/mavlink/mavlink_ftp.cpp +++ b/src/modules/mavlink/mavlink_ftp.cpp @@ -204,6 +204,10 @@ MavlinkFTP::_process_request(Request *req) errorCode = _workRemoveFile(payload); break; + case kCmdRename: + errorCode = _workRename(payload); + break; + case kCmdTruncateFile: errorCode = _workTruncateFile(payload); break; @@ -629,6 +633,33 @@ MavlinkFTP::_workReset(PayloadHeader* payload) return kErrNone; } +/// @brief Responds to a Rename command +MavlinkFTP::ErrorCode +MavlinkFTP::_workRename(PayloadHeader* payload) +{ + char oldpath[kMaxDataLength]; + char newpath[kMaxDataLength]; + + char *ptr = _data_as_cstring(payload); + size_t oldpath_sz = strlen(ptr); + + if (oldpath_sz == payload->size) { + // no newpath + errno = EINVAL; + return kErrFailErrno; + } + + strncpy(oldpath, ptr, kMaxDataLength); + strncpy(newpath, ptr + oldpath_sz + 1, kMaxDataLength); + + if (rename(oldpath, newpath) == 0) { + payload->size = 0; + return kErrNone; + } else { + return kErrFailErrno; + } +} + /// @brief Responds to a RemoveDirectory command MavlinkFTP::ErrorCode MavlinkFTP::_workRemoveDirectory(PayloadHeader* payload) diff --git a/src/modules/mavlink/mavlink_ftp.h b/src/modules/mavlink/mavlink_ftp.h index bde8d7ec5..0fbd010be 100644 --- a/src/modules/mavlink/mavlink_ftp.h +++ b/src/modules/mavlink/mavlink_ftp.h @@ -98,6 +98,7 @@ public: kCmdRemoveDirectory, ///< Removes Directory at <path>, must be empty kCmdOpenFileWO, ///< Opens file at <path> for writing, returns <session> kCmdTruncateFile, ///< Truncate file at <path> to <offset> length + kCmdRename, ///< Rename <path1> to <path2> kRspAck = 128, ///< Ack response kRspNak ///< Nak response @@ -152,6 +153,7 @@ private: ErrorCode _workCreateDirectory(PayloadHeader *payload); ErrorCode _workRemoveFile(PayloadHeader *payload); ErrorCode _workTruncateFile(PayloadHeader *payload); + ErrorCode _workRename(PayloadHeader *payload); static const unsigned kRequestQueueSize = 2; ///< Max number of queued requests Request _request_bufs[kRequestQueueSize]; ///< Request buffers which hold work |