diff --git a/src/tools/singlejar/combiners.cc b/src/tools/singlejar/combiners.cc index 26fcc58004fc91..7b8b773e68e916 100644 --- a/src/tools/singlejar/combiners.cc +++ b/src/tools/singlejar/combiners.cc @@ -67,8 +67,8 @@ void *Concatenator::OutputEntry(bool compress) { lh->signature(); lh->version(20); lh->bit_flag(0x0); - lh->last_mod_file_time(1); // 00:00:01 - lh->last_mod_file_date(33); // 1980-01-01 + lh->last_mod_file_time(1); // 00:00:01 + lh->last_mod_file_date(30 << 9 | 1 << 5 | 1); // 2010-01-01 lh->crc32(0x12345678); lh->compressed_file_size32(0); lh->file_name(filename_.c_str(), filename_.size()); diff --git a/src/tools/singlejar/output_jar.cc b/src/tools/singlejar/output_jar.cc index 52a80de256575d..202a4be6b63304 100644 --- a/src/tools/singlejar/output_jar.cc +++ b/src/tools/singlejar/output_jar.cc @@ -298,6 +298,9 @@ bool OutputJar::Open() { return true; } +// January 1, 2010 as a DOS date +static const uint16_t kDefaultDate = 30 << 9 | 1 << 5 | 1; + bool OutputJar::AddJar(int jar_path_index) { const std::string &input_jar_path = options_->input_jars[jar_path_index].first; @@ -450,7 +453,7 @@ bool OutputJar::AddJar(int jar_path_index) { off64_t local_header_offset = Position(); // When normalize_timestamps is set, entry's timestamp is to be set to - // 01/01/1980 00:00:00 (or to 01/01/1980 00:00:02, if an entry is a .class + // 01/01/2010 00:00:00 (or to 01/01/2010 00:00:02, if an entry is a .class // file). This is somewhat expensive because we have to copy the local // header to memory as input jar is memory mapped as read-only. Try to copy // as little as possible. @@ -462,7 +465,7 @@ bool OutputJar::AddJar(int jar_path_index) { normalized_time = 1; } lh_field_to_remove = lh->unix_time_extra_field(); - fix_timestamp = jar_entry->last_mod_file_date() != 33 || + fix_timestamp = jar_entry->last_mod_file_date() != kDefaultDate || jar_entry->last_mod_file_time() != normalized_time || lh_field_to_remove != nullptr; } @@ -489,7 +492,7 @@ bool OutputJar::AddJar(int jar_path_index) { } else { memcpy(lh_new, lh, lh_size); } - lh_new->last_mod_file_date(33); + lh_new->last_mod_file_date(kDefaultDate); lh_new->last_mod_file_time(normalized_time); // Now write these few bytes and adjust read/write positions accordingly. if (!WriteBytes(lh_new, lh_new->size())) { @@ -549,9 +552,9 @@ void OutputJar::WriteEntry(void *buffer) { // https://msdn.microsoft.com/en-us/library/9kkf9tah.aspx // ("32-Bit Windows Time/Date Formats") if (options_->normalize_timestamps) { - // Regular "normalized" timestamp is 01/01/1980 00:00:00, while for the - // .class file it is 01/01/1980 00:00:02 - entry->last_mod_file_date(33); + // Regular "normalized" timestamp is 01/01/2010 00:00:00, while for the + // .class file it is 01/01/2010 00:00:02 + entry->last_mod_file_date(kDefaultDate); entry->last_mod_file_time( ends_with(entry->file_name(), entry->file_name_length(), ".class") ? 1 : 0); @@ -757,7 +760,7 @@ void OutputJar::AppendToDirectoryBuffer(const CDH *cdh, off64_t lh_pos, out_cdh->local_header_offset32(lh_pos_needs64 ? 0xFFFFFFFF : lh_pos); if (fix_timestamp) { out_cdh->last_mod_file_time(normalized_time); - out_cdh->last_mod_file_date(33); + out_cdh->last_mod_file_date(kDefaultDate); } } diff --git a/src/tools/singlejar/output_jar_simple_test.cc b/src/tools/singlejar/output_jar_simple_test.cc index 5f83acbe7dfa8f..96d1c7ae14048c 100644 --- a/src/tools/singlejar/output_jar_simple_test.cc +++ b/src/tools/singlejar/output_jar_simple_test.cc @@ -504,7 +504,7 @@ TEST_F(OutputJarSimpleTest, Normalize) { "--classpath_resources", cp_resource_path}); // Scan all entries, verify that *.class entries have timestamp - // 01/01/1980 00:00:02 and the rest have the timestamp of 01/01/1980 00:00:00. + // 01/01/2010 00:00:02 and the rest have the timestamp of 01/01/2010 00:00:00. InputJar input_jar; ASSERT_TRUE(input_jar.Open(out_path)); const LH *lh; @@ -515,8 +515,8 @@ TEST_F(OutputJarSimpleTest, Normalize) { << entry_name << " modification date"; EXPECT_EQ(lh->last_mod_file_time(), cdh->last_mod_file_time()) << entry_name << " modification time"; - EXPECT_EQ(33, cdh->last_mod_file_date()) - << entry_name << " modification date should be 01/01/1980"; + EXPECT_EQ(15393, cdh->last_mod_file_date()) + << entry_name << " modification date should be 01/01/2010"; auto n = entry_name.size() - strlen(".class"); if (0 == strcmp(entry_name.c_str() + n, ".class")) { EXPECT_EQ(1, cdh->last_mod_file_time())