Attach timestamp to ringbuffer generated files
The file last modified time expressed in seconds from epoch is
attached to only the archived version of the file that is passed
to dumpstate.
Files stored on the device will still have no timestamp in their name.
Bug: 159808285
Test: manual verification
adb root
adb shell lshal debug android.hardware.wifi@1.5::IWifi >> archive.cpio
cpio -iv < archive.cpio
Verify that a timestamp is attached to the filename at the end:
connectivity_events_rbhOVjYpDdNY-1597364258
Change-Id: Iee0c2b37fc1d27cb979ec9125461416cd2d02549
diff --git a/wifi/1.5/default/wifi_chip.cpp b/wifi/1.5/default/wifi_chip.cpp
index 069fd65..8f0e000 100644
--- a/wifi/1.5/default/wifi_chip.cpp
+++ b/wifi/1.5/default/wifi_chip.cpp
@@ -281,9 +281,6 @@
continue;
}
std::string cur_file_name(dp->d_name);
- // string.size() does not include the null terminator. The cpio FreeBSD
- // file header expects the null character to be included in the length.
- const size_t file_name_len = cur_file_name.size() + 1;
struct stat st;
const std::string cur_file_path = kTombstoneFolderPath + cur_file_name;
if (stat(cur_file_path.c_str(), &st) == -1) {
@@ -297,8 +294,15 @@
n_error++;
continue;
}
+ std::string file_name_with_last_modified_time =
+ cur_file_name + "-" + std::to_string(st.st_mtime);
+ // string.size() does not include the null terminator. The cpio FreeBSD
+ // file header expects the null character to be included in the length.
+ const size_t file_name_len =
+ file_name_with_last_modified_time.size() + 1;
unique_fd file_auto_closer(fd_read);
- if (!cpioWriteHeader(out_fd, st, cur_file_name.c_str(),
+ if (!cpioWriteHeader(out_fd, st,
+ file_name_with_last_modified_time.c_str(),
file_name_len)) {
return ++n_error;
}