Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 324200 - [test][transport] CacheManager sets lastModified incorrectly when downloading files
Summary: [test][transport] CacheManager sets lastModified incorrectly when downloading...
Status: RESOLVED FIXED
Alias: None
Product: Equinox
Classification: Eclipse Project
Component: p2 (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows Vista
: P3 normal with 4 votes (vote)
Target Milestone: Juno   Edit
Assignee: P2 Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 343513 (view as bug list)
Depends on:
Blocks:
 
Reported: 2010-09-01 10:20 EDT by Tobias Oberlies CLA
Modified: 2012-04-20 15:32 EDT (History)
6 users (show)

See Also:


Attachments
Fix v01 (2.41 KB, patch)
2010-11-27 08:01 EST, Beyhan Veliev CLA
pascal: iplog+
pascal: review+
Details | Diff
Test case for this bug (6.75 KB, application/zip)
2011-10-17 14:13 EDT, Beyhan Veliev CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Oberlies CLA 2010-09-01 10:20:31 EDT
Build Identifier: Eclipse Helios ("SR 0")

When org.eclipse.equinox.internal.p2.repository.CacheManager.updateCache downloads a file, it implicitly sets the lastModified timestamp of the cache file to the current time. This is incorrect: the download is a normal copy operation and therefore the local file that is being written should have the same lastModified timestamp as the server file.

As a consequence of this bug, a stale file may be kept in the cache.

Reproducible: Always

Steps to Reproduce:
Be A, B, C times, with A < B < C
1. At time C, download a file with the CacheManager.createCache that has last been modified at time A (e.g. a file content.xml by loading a repository with a MetadataRepositoryManager); the local file is marked with last modified timestamp C.
2. Then replace the server file with a newer file that was last modified at time B. The file is newer that the cached file.
3. Next, request the same file with CacheManager.createCache; the method does not download the newer file (modified at time B) but returns the older, stale file (modified at time A).
Comment 1 Beyhan Veliev CLA 2010-11-22 09:23:38 EST
This bug has a high priority for me because updates can be lost due to time zone differences. E.g suppose that we have a server in time zone GMT and a client in time zone GMT +4. On the server is an update available and the client performs a normal P2 update. In this case the cache on the client can be up to 4 hours older than server's content due to the time difference. This means all new updates on the server within the next 4 hours will have no effect for this client. 

Due to this bug downgrades are not possible without touching the modification timestamp of your old repository.

IMHO it should be enough to set the modification timestamp of a downloaded cache file in CacheManager.createCache to correspond to server's modification timestamp for this resource. Also the check whether something changed or not shouldn't be "lastModifiedRemote > lastModified" instead "lastModifiedRemote != lastModified" to support downgrades. I will provide a patch.
Comment 2 Beyhan Veliev CLA 2010-11-27 08:01:23 EST
Created attachment 183976 [details]
Fix v01

Fix for two issues
1. Local cache file that is being written should have the
same lastModified timestamp as the server's file. Avoids time zone problems

2. Downgrades are not possible without touching the modification
timestamp of your old repository. (See stale check "lastModifiedRemote > lastModified")
Comment 3 Pascal Rapicault CLA 2010-12-23 19:22:25 EST
Could you please provide a test case for this. Thx.
Comment 4 Beyhan Veliev CLA 2011-04-21 12:07:51 EDT
*** Bug 343513 has been marked as a duplicate of this bug. ***
Comment 5 Pascal Rapicault CLA 2011-05-02 14:49:11 EDT
Tobias, Beyhan, could you please provide a test case?
Assigning to Jeff since the patch got provided by EclipseSource :)
Comment 6 Pascal Rapicault CLA 2011-05-09 23:14:33 EDT
Comment on attachment 183976 [details]
Fix v01

I've released this patch.
Comment 7 Pascal Rapicault CLA 2011-05-09 23:15:22 EDT
I would still appreciate a patch. Thx.
Comment 8 Pascal Rapicault CLA 2011-05-09 23:15:44 EDT
I meant I would still appreciate a test case :)
Comment 9 Beyhan Veliev CLA 2011-05-10 03:22:10 EDT
(In reply to comment #8)
> I meant I would still appreciate a test case :)

Thank you Pascal for releasing this patch. I'll provide some tests. Are there any CacheManager tests?
Comment 10 Pascal Rapicault CLA 2011-05-10 08:37:47 EDT
There is no explicit test for this. It is probably simpler to just create a new test class for this validating the behaviour you've changed. Thx in advance.
Comment 11 Pascal Rapicault CLA 2011-05-10 08:38:36 EDT
Forgot to mention, in other contexts I have tested something like that simply by manually changing the timestamp on the file on disk.
Comment 12 Thomas Watson CLA 2011-06-08 11:31:12 EDT
Move all 3.8 bugs to Juno.
Comment 13 Beyhan Veliev CLA 2011-10-17 14:13:18 EDT
Created attachment 205360 [details]
Test case for this bug

It seems that this patch has been contributed to 3.7. Here are also the test cases which i promised. Therefore, this bug can be closed
Comment 14 Christian Sell CLA 2012-04-20 06:52:14 EDT
why is this bug still ASSIGNED, when the patch is already part of the Indigo release?
Comment 15 Pascal Rapicault CLA 2012-04-20 15:32:19 EDT
The code has been released a while back. I finally released the test.