Change metadata merge of Date/DateTime to take max value
ClosedPublic

Authored by alvinhochun on Oct 29 2017, 8:28 AM.

Details

Summary

There are two issues:

  • QDate::fromJulianDay and QDateTime::toSecsSinceEpoch are static functions which return the result value, so the calls in the code are effectively no-op, so the merged value is replaced with a default-initialized value.
  • It doesn't make sense to add two absolute time values together (what meaningful result would we get by adding the dates of today and tomorrow?)
Test Plan

Hi, @alvinhochun!

The patch is basically fine. But how about making the merge oparetion use maximum time of the two? That would be quite meaningful for "creation time" and "last modification" time.

If you agree with the statement, please push the 'max' version. If not, just push what you have now.

Make sense, that's one way to change it.

Diff Detail

Repository
R37 Krita
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
alvinhochun created this revision.Oct 29 2017, 8:28 AM
Restricted Application added a subscriber: woltherav. · View Herald TranscriptOct 29 2017, 8:28 AM
rempt added a subscriber: rempt.Oct 29 2017, 12:07 PM

I am not sure what the original code was intended to do, but asserting on it probably would break loading jpegs with dates in the metadata?

dkazakov requested changes to this revision.Oct 30 2017, 9:12 AM
dkazakov added a subscriber: dkazakov.

As far as I can tell the code is not a noop, it sums up two dates/times. At least that is what it is expected to do. As far as I can guess, the summing up may happen while merging two layers with metadata.

There is also a problem that the patch doesn't apply to master anymore :(

This revision now requires changes to proceed.Oct 30 2017, 9:12 AM

And before the Boud's commit, when the patch could apply successfully, it didn't compile on Qt 5.6, which is still the version we use on Linux :(

As far as I can tell the code is not a noop, it sums up two dates/times. At least that is what it is expected to do. As far as I can guess, the summing up may happen while merging two layers with metadata.

Sure, its original intention would be to sum up two Date/DateTime values, but as I said it does not make sense. Even if the addition result is assigned properly, the result would be meaningless.

And you're right that the code isn't a noop... it's something else: It replaces the value with a default-initialized QDate/QDateTime and completely discards the original values. QDate::fromJulianDay and QDateTime::toSecsSinceEpoch are static functions, which means they don't operate on and cannot change the instance. Some code linting would've caught it.

Anyway, the code is definitely broken in some way. I would still suggest removing the broken addition and just keep the original value, but changing the assert to a warning log message. It looks like the code might not even be called at all according to Boud (see below).

There is also a problem that the patch doesn't apply to master anymore :(

And before the Boud's commit, when the patch could apply successfully, it didn't compile on Qt 5.6, which is still the version we use on Linux :(

Yeah, Boud fixed the build errors with a series of commits. This patch alone would not have fixed build issues on Qt 5.6. (843d4348989ac1f49f705a8c9b8f98576cdbf1cc is the missing change.)


P.S. My previous irc conversation with Boud:

<boud> windragon: outch, I'll have to ifdef that
[...]
<windragon> boud: does it ever do QDateTime arithmetic?
<windragon> boud: perhaps just change it to a warning log instead
<windragon> boud: idk either there is a bug in the original code and it should store the addition result properly, or that it doesn't ever get called at all
<boud> windragon: yes, it's pretty weird... only cyrille probably can remember how this was meant.
<boud> And I don't know even know when the whole function would be called
<boud> I've pushed an ifdef, but for what I can see, it probably is never called with a QDateTime
<boud> it's called from here: https://pastebin.com/jbYVKAkK
(content:)

mergeEntry(dst, srcs, dcSchema, "contributor");
mergeEntry(dst, srcs, dcSchema, "creator");
mergeEntry(dst, srcs, dcSchema, "publisher");
mergeEntry(dst, srcs, dcSchema, "subject");
mergeEntry(dst, srcs, XMPRightsSchema, "Owner");
mergeEntry(dst, srcs, XMPSchema, "Identifier");

<windragon> I'll change it to a warning log message and update the patch then
<windragon> maybe later
<boud> okay
<boud> I;'m not even sure that "merging metadata" should be expressed as adding.
<boud> of course, Krita might very well be the only application that merges metadata when layers are merged; I don't think any other application keeps per-layer metadata.

Changed to output a warning log message.

dkazakov accepted this revision.Nov 20 2017, 1:31 PM

Hi, @alvinhochun!

The patch is basically fine. But how about making the merge oparetion use maximum time of the two? That would be quite meaningful for "creation time" and "last modification" time.

If you agree with the statement, please push the 'max' version. If not, just push what you have now.

This revision is now accepted and ready to land.Nov 20 2017, 1:31 PM
alvinhochun retitled this revision from Change broken Date/DateTime addition in KisMetaData::Value to safe assert to Change metadata merge of Date/DateTime to take max value.Nov 22 2017, 2:33 PM
alvinhochun edited the summary of this revision. (Show Details)
alvinhochun edited the test plan for this revision. (Show Details)
This revision was automatically updated to reflect the committed changes.