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