1From 122d8d7e63f5c5c2bf81143ef655e964d3982cfd Mon Sep 17 00:00:00 2001 2From: Jeffy Chen <jeffy.chen@rock-chips.com> 3Date: Fri, 27 May 2022 12:43:19 +0800 4Subject: [PATCH] MtpServer: Support creation time 5 6Only available on boost >= 1.75.0 and kernel >= 4.11. 7 8Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com> 9--- 10 CMakeLists.txt | 3 ++- 11 include/MtpDatabase.h | 3 ++- 12 server/UbuntuMtpDatabase.h | 9 ++++++++- 13 src/MtpServer.cpp | 9 +++++++-- 14 tests/MockMtpDatabase.h | 3 ++- 15 5 files changed, 21 insertions(+), 6 deletions(-) 16 17diff --git a/CMakeLists.txt b/CMakeLists.txt 18index 707b7f8..a2d7bd5 100644 19--- a/CMakeLists.txt 20+++ b/CMakeLists.txt 21@@ -13,7 +13,8 @@ set(MTP_VERSION_MAJOR 1) 22 set(MTP_VERSION_MINOR 0) 23 set(MTP_VERSION_PATCH 0) 24 25-find_package(Boost REQUIRED COMPONENTS thread system filesystem unit_test_framework) 26+# Request 1.75.0 for filesystem creation_time operation. 27+find_package(Boost 1.75.0 REQUIRED COMPONENTS thread system filesystem unit_test_framework) 28 pkg_check_modules(DBUSCPP REQUIRED dbus-c++-1) 29 pkg_check_modules(GLOG REQUIRED libglog) 30 31diff --git a/include/MtpDatabase.h b/include/MtpDatabase.h 32index c72964c..203b33f 100644 33--- a/include/MtpDatabase.h 34+++ b/include/MtpDatabase.h 35@@ -45,7 +45,8 @@ public: 36 MtpObjectHandle parent, 37 MtpStorageID storage, 38 uint64_t size, 39- time_t modified) = 0; 40+ time_t modified, 41+ time_t created) = 0; 42 43 // called to report success or failure of the SendObject file transfer 44 // success should signal a notification of the new object's creation, 45diff --git a/server/UbuntuMtpDatabase.h b/server/UbuntuMtpDatabase.h 46index 73200de..6078c31 100644 47--- a/server/UbuntuMtpDatabase.h 48+++ b/server/UbuntuMtpDatabase.h 49@@ -68,6 +68,7 @@ private: 50 std::string path; 51 int watch_fd; 52 std::time_t last_modified; 53+ std::time_t creation; 54 }; 55 56 MtpServer* local_server; 57@@ -134,6 +135,7 @@ private: 58 entry.object_size = 0; 59 entry.watch_fd = setup_dir_inotify(p); 60 entry.last_modified = last_write_time(p); 61+ entry.creation = creation_time(p); 62 63 db.insert( std::pair<MtpObjectHandle, DbEntry>(handle, entry) ); 64 65@@ -150,6 +152,7 @@ private: 66 entry.object_format = guess_object_format(p.extension().string()); 67 entry.object_size = file_size(p); 68 entry.last_modified = last_write_time(p); 69+ entry.creation = creation_time(p); 70 71 VLOG(1) << "Adding \"" << p.string() << "\""; 72 73@@ -206,6 +209,7 @@ private: 74 entry.object_size = 0; 75 entry.watch_fd = setup_dir_inotify(p); 76 entry.last_modified = last_write_time(p); 77+ entry.creation = creation_time(p); 78 79 db.insert( std::pair<MtpObjectHandle, DbEntry>(handle, entry) ); 80 81@@ -224,6 +228,7 @@ private: 82 entry.object_size = 0; 83 entry.watch_fd = setup_dir_inotify(p.parent_path()); 84 entry.last_modified = 0; 85+ entry.creation = 0; 86 } 87 } 88 } 89@@ -399,7 +404,8 @@ public: 90 MtpObjectHandle parent, 91 MtpStorageID storage, 92 uint64_t size, 93- time_t modified) 94+ time_t modified, 95+ time_t created) 96 { 97 DbEntry entry; 98 MtpObjectHandle handle = counter; 99@@ -417,6 +423,7 @@ public: 100 entry.object_format = format; 101 entry.object_size = size; 102 entry.last_modified = modified; 103+ entry.creation = created; 104 105 db.insert( std::pair<MtpObjectHandle, DbEntry>(handle, entry) ); 106 107diff --git a/src/MtpServer.cpp b/src/MtpServer.cpp 108index fb73ac3..99897c4 100644 109--- a/src/MtpServer.cpp 110+++ b/src/MtpServer.cpp 111@@ -786,7 +786,8 @@ MtpResponseCode MtpServer::doGetObjectInfo() { 112 mData.putUInt32(info.mAssociationDesc); 113 mData.putUInt32(info.mSequenceNumber); 114 mData.putString(info.mName); 115- mData.putEmptyString(); // date created 116+ formatDateTime(info.mDateCreated, date, sizeof(date)); 117+ mData.putString(date); // date created 118 formatDateTime(info.mDateModified, date, sizeof(date)); 119 mData.putString(date); // date modified 120 mData.putEmptyString(); // keywords 121@@ -969,6 +970,10 @@ MtpResponseCode MtpServer::doSendObjectInfo() { 122 if (!parseDateTime(modified, modifiedTime)) 123 modifiedTime = 0; 124 125+ time_t createdTime; 126+ if (!parseDateTime(created, createdTime)) 127+ createdTime = 0; 128+ 129 if (path[path.size() - 1] != '/') 130 path += "/"; 131 path += (const char *)name; 132@@ -988,7 +993,7 @@ MtpResponseCode MtpServer::doSendObjectInfo() { 133 VLOG(2) << "path: " << path.c_str() << " parent: " << parent 134 << " storageID: " << std::hex << storageID << std::dec; 135 MtpObjectHandle handle = mDatabase->beginSendObject(path.c_str(), 136- format, parent, storageID, mSendObjectFileSize, modifiedTime); 137+ format, parent, storageID, mSendObjectFileSize, modifiedTime, createdTime); 138 if (handle == kInvalidObjectHandle) { 139 return MTP_RESPONSE_GENERAL_ERROR; 140 } 141diff --git a/tests/MockMtpDatabase.h b/tests/MockMtpDatabase.h 142index 1a10857..61f6817 100644 143--- a/tests/MockMtpDatabase.h 144+++ b/tests/MockMtpDatabase.h 145@@ -88,7 +88,8 @@ public: 146 MtpObjectHandle parent, 147 MtpStorageID storage, 148 uint64_t size, 149- time_t modified) 150+ time_t modified, 151+ time_t created) 152 { 153 return 1; 154 } 155-- 1562.20.1 157 158