diff options
author | Ethan Yonker <dees_troy@teamw.in> | 2014-09-04 19:59:27 +0200 |
---|---|---|
committer | Ethan Yonker <dees_troy@teamw.in> | 2014-09-04 20:05:35 +0200 |
commit | 241a3ce4c5ff883c160754e0aebd1e1b0894d332 (patch) | |
tree | e39901d3a8b91ad599ec71754dfeba7cdea8dcc1 /mtp/node.cpp | |
parent | MTP Fix rename in Windows (diff) | |
download | android_bootable_recovery-241a3ce4c5ff883c160754e0aebd1e1b0894d332.tar android_bootable_recovery-241a3ce4c5ff883c160754e0aebd1e1b0894d332.tar.gz android_bootable_recovery-241a3ce4c5ff883c160754e0aebd1e1b0894d332.tar.bz2 android_bootable_recovery-241a3ce4c5ff883c160754e0aebd1e1b0894d332.tar.lz android_bootable_recovery-241a3ce4c5ff883c160754e0aebd1e1b0894d332.tar.xz android_bootable_recovery-241a3ce4c5ff883c160754e0aebd1e1b0894d332.tar.zst android_bootable_recovery-241a3ce4c5ff883c160754e0aebd1e1b0894d332.zip |
Diffstat (limited to 'mtp/node.cpp')
-rwxr-xr-x | mtp/node.cpp | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/mtp/node.cpp b/mtp/node.cpp index 79936c4a4..1a09c85ae 100755 --- a/mtp/node.cpp +++ b/mtp/node.cpp @@ -103,24 +103,27 @@ void Node::addProperties(int storageID, int parent_object) { struct stat st; int mFormat = 0; uint64_t puid; + off_t file_size = 0; + std::string mtimeStr = "00101T000000"; + std::string atimeStr = "00101T000000"; std::string mtpidStr = static_cast<std::ostringstream*>( &(std::ostringstream() << mtpid) )->str(); std::string storageIDStr = static_cast<std::ostringstream*>( &(std::ostringstream() << storageID) )->str(); std::string puidStr = storageIDStr + mtpidStr; if ( ! (std::istringstream(puidStr) >> puid) ) puid = 0; - stat(getPath().c_str(), &st); - std::string mtimeStr = static_cast<std::ostringstream*>( &(std::ostringstream() << st.st_mtime) )->str(); - std::string atimeStr = static_cast<std::ostringstream*>( &(std::ostringstream() << st.st_atime) )->str(); - if (S_ISDIR(st.st_mode)) { - mFormat = MTP_FORMAT_ASSOCIATION; // folder - } - else { - mFormat = MTP_FORMAT_UNDEFINED; // file + mFormat = MTP_FORMAT_UNDEFINED; // file + if (lstat(getPath().c_str(), &st) == 0) { + file_size = st.st_size; + if (S_ISDIR(st.st_mode)) + mFormat = MTP_FORMAT_ASSOCIATION; // folder + mtimeStr = static_cast<std::ostringstream*>( &(std::ostringstream() << st.st_mtime) )->str(); + atimeStr = static_cast<std::ostringstream*>( &(std::ostringstream() << st.st_atime) )->str(); } + addProperty(MTP_PROPERTY_STORAGE_ID, storageID, "", MTP_TYPE_UINT32); addProperty(MTP_PROPERTY_OBJECT_FORMAT, mFormat, "", MTP_TYPE_UINT16); addProperty(MTP_PROPERTY_PROTECTION_STATUS, 0, "", MTP_TYPE_UINT16); - addProperty(MTP_PROPERTY_OBJECT_SIZE, st.st_size, "", MTP_TYPE_UINT64); + addProperty(MTP_PROPERTY_OBJECT_SIZE, file_size, "", MTP_TYPE_UINT64); addProperty(MTP_PROPERTY_OBJECT_FILE_NAME, 0, basename(getPath().c_str()), MTP_TYPE_STR); MTPD("mtpid: %i, filename: '%s', parent object: %i\n", mtpid, basename(getPath().c_str()), parent_object); addProperty(MTP_PROPERTY_DATE_MODIFIED, 0, mtimeStr, MTP_TYPE_STR); |