if (!file_exists($local) || update_delete_file_if_stale($local)) {
    return system_retrieve_file($url, $local, FALSE, FILE_EXISTS_REPLACE);
  }
  else {
    return $local;
  }

We'll never use the local cache of a remote file since update_delete_file_if_stale() is a void function.

The patch should:

  • change update_delete_file_if_stale() to return TRUE if something is deleted and FALSE if not.
  • update UpdateDeleteFileIfStaleTest to test the return value.
Contributor tasks needed
Task Novice task? Contributor instructions Complete?
Create a patch Y Instructions
Add automated tests (if possible) Y Instructions
Review patch to ensure that it fixes the issue, stays within scope, is properly documented, and follows coding standards Y Instructions
CommentFileSizeAuthor
#48 2303323.45_48.interdiff.txt857 bytesdww
#48 2303323-48.patch2.74 KBdww
#48 2303323-48.test-only.patch3.52 KBdww
#46 2303323-45.patch2.69 KBdww
#46 2303323-46.test-only.patch3.47 KBdww
#45 2303323.43_45.interdiff.txt2.44 KBdww
#45 2303323-45.patch2.69 KBdww
#43 2303323.41_43.interdiff.txt490 bytesdww
#43 2303323-43.patch2.79 KBdww
#41 2303323.40_41.interdiff.txt1.58 KBdww
#41 2303323-41.patch2.78 KBdww
#40 interdiff_33-40.txt1.13 KBvsujeetkumar
#40 2303323_40.patch2.9 KBvsujeetkumar
#33 interdiff-29-33.txt702 bytesiyyappan.govind
#33 2303323-33.patch3.02 KBiyyappan.govind
#29 2303323-29.patch3.02 KBquietone
#29 interdiff-17-29.txt4.72 KBquietone
#23 update_manager_file_get-2303323-17.patch2.7 KBquietone
#20 update_manager_file_get-2303323-20_fail.patch1.79 KBquietone
#17 update_manager_file_get-2303323-17.patch2.7 KBjp.stacey
#12 update_manager_file_get-fetch-stale-files-2303323-12-test-only.patch665 bytestadityar
#12 update_manager_file_get-fetch-stale-files-2303323-12.patch1.56 KBtadityar
#6 interdiff-2303323-5-6.txt996 bytesamitgoyal
#6 update_manager_file_get-fetch-stale-files-2303323-6.patch1.56 KBamitgoyal
#5 interdiff-2303323-3-5.txt1.14 KBer.pushpinderrana
#5 update_manager_file_get-fetch-stale-files-2303323-5.patch1.54 KBer.pushpinderrana
#3 update_manager_file_get-fetch-stale-files-2303323-3.patch1.53 KBjoshi.rohit100
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

alexpott’s picture

Issue summary: View changes
alexpott’s picture

Issue summary: View changes
joshi.rohit100’s picture

Status: Active » Needs review
FileSize
1.53 KB

please review now.

Berdir’s picture

Status: Needs review » Needs work
  1. +++ b/core/modules/update/src/Tests/UpdateDeleteFileIfStaleTest.php
    @@ -45,9 +45,9 @@ function testUpdateDeleteFileIfStale() {
     
    -    $this->assertFalse(is_file($file_path));
    +		$this->assertTrue($deleted, 'Successfull deleted the stale file');
    

    Always use two spaces instead of tabs.

  2. +++ b/core/modules/update/update.module
    @@ -741,14 +741,19 @@ function update_clear_update_disk_cache() {
      * @param $path
      *   A string containing a file path or (streamwrapper) URI.
    + * @return
    + *	 TRUE if delete file successfully, FALSE otherwise.
    

    There must be an empty line above @return and @return must be followed by the type (bool)

er.pushpinderrana’s picture

Status: Needs work » Needs review
FileSize
1.54 KB
1.14 KB

Please review updated patch.

amitgoyal’s picture

Please review update patch with minor fixes.

vlad.n’s picture

update_manager_file_get-fetch-stale-files-2303323-6.patch still applies cleanly at f07bcff .

nuwe’s picture

update_manager_file_get-fetch-stale-files-2303323-6.patch still applies cleanly at f07bcff

star-szr’s picture

Status: Needs review » Needs work

This should have a test-only patch uploaded to show that the updated test fails and catches the bug.

https://www.drupal.org/contributor-tasks/write-tests

tadityar’s picture

Added the test-only patch.

Status: Needs review » Needs work
tadityar’s picture

Status: Needs work » Needs review

err.. that one was supposed to fail anyway

dimaro’s picture

I reviewed this issue and for me work as expected. Also it follows the coding standars. RTBC?

jp.stacey’s picture

Looking at this as part of Sprint Weekend 2016.

jp.stacey’s picture

The patch as it stands does test the return value of update_delete_file_if_stale(). However, it no longer tests that the file is actually deleted!

I've modified the test so it checks:

1. the file exists.
2. trying to delete a non-stale file returns FALSE.
3. the file is deleted when stale.
4. trying to delete a stale file returns TRUE.

All six assertions in the test pass on my dev build, so submitting for review.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

quietone’s picture

The patch applies to 8.2.x and looks good to me. The added tests properly checks if the file was deleted and the status of the returned boolean.

Also, since #17 doesn't include a fail patch, I've added one. Also retesting #17 on 8.2.x

Status: Needs review » Needs work

The last submitted patch, 20: update_manager_file_get-2303323-20_fail.patch, failed testing.

quietone’s picture

So, the fail patch in #20 shows that even though the stale file is deleted a success (true) is not returned. The patch in #17 is the fix and looks good to me.

But this is tagged with Needs change record, so there is still work to do.

quietone’s picture

Status: Needs work » Needs review
FileSize
2.7 KB

RE uploading the patch in #17, the latest working one, so this can be set to NR.

Does this need a change record?

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

quietone’s picture

Version: 8.8.x-dev » 8.9.x-dev
FileSize
4.72 KB
3.02 KB

An attempt at a reroll and move to 8.9.x

dww’s picture

Title: update_manager_file_get will always fetch remote files » update_manager_file_get() will always fetch remote files
Status: Needs review » Needs work

Just seeing this issue for the first time.

Mostly looks great. Love the expanded test coverage. The change itself is small and good. One very minor quibble:

+++ b/core/modules/update/tests/src/Kernel/UpdateDeleteFileIfStaleTest.php
@@ -36,10 +51,12 @@ public function testUpdateDeleteFileIfStale() {
+    // Now attempt to delete the file now; as it should be considered stale,

We don't need "now" twice in this comment.

Otherwise, I wonder if we want a better title for this issue for git history reasons. The title talks about update_manager_file_get(), but only change here is in update_delete_file_if_stale().

Finally, I agree we probably need a CR for this.

Thanks!
-Derek

dww credited Alan D..

dww’s picture

A little git archeology. This bug came in when update_delete_file_if_stale() was first added at #605318: Add some garbage collection to the update manager. Not sure how we missed it. ;) That issue was re-opened at #605318-67: Add some garbage collection to the update manager for exactly this problem. I'm going to go ahead and re-close that one in favor of this, since the patch here is in better shape than the latest over there. However, crediting Alan D. so their contribution at #605318 is acknowledged.

iyyappan.govind’s picture

Hi Dww,

As per suggestion I have updated the patch.

Before

+++ b/core/modules/update/tests/src/Kernel/UpdateDeleteFileIfStaleTest.php
@@ -36,10 +51,12 @@ public function testUpdateDeleteFileIfStale() {
+    // Now attempt to delete the file now; as it should be considered stale,

Now

+++ b/core/modules/update/tests/src/Kernel/UpdateDeleteFileIfStaleTest.php
@@ -36,10 +51,12 @@ public function testUpdateDeleteFileIfStale() {
+    // Now attempt to delete the file; as it should be considered stale,

Thanks

iyyappan.govind’s picture

iyyappan.govind’s picture

Status: Needs work » Needs review

Changing status

dww’s picture

Title: update_manager_file_get() will always fetch remote files » update_delete_file_if_stale() must return a value or update_manager_file_get() will always fetch remote files
Status: Needs review » Needs work

Attempt at resolving #30 with a more complete title.

Sorry I didn't notice before, but one other minor optional change:

+++ b/core/modules/update/tests/src/Kernel/UpdateDeleteFileIfStaleTest.php
@@ -27,6 +27,21 @@ public function testUpdateDeleteFileIfStale() {
+    $this->assertTrue(is_file($file_path), 'Non-stale file is not deleted.');
+    // Test return status $deleted is consistent.
+    $this->assertFalse($deleted, 'Stale file deletion reports failure correctly.');

@@ -36,10 +51,12 @@ public function testUpdateDeleteFileIfStale() {
+    $this->assertFalse(is_file($file_path), 'Stale file is deleted.');
+    // As before, test return status $deleted is consistent.
+    $this->assertTrue($deleted, 'Stale file deletion reports success correctly.');

I don't think these comments are needed given the assertions themselves.

If we keep them, we don't need "As before, ".

However, NW because it still needs the CR.

Thanks!
-Derek

jungle’s picture

+++ b/core/modules/update/tests/src/Kernel/UpdateDeleteFileIfStaleTest.php
@@ -27,6 +27,21 @@ public function testUpdateDeleteFileIfStale() {
+    $this->assertTrue(is_file($file_path), 'Non-stale file is not deleted.');

@@ -36,10 +51,12 @@ public function testUpdateDeleteFileIfStale() {
+    $this->assertTrue($deleted, 'Stale file deletion reports success correctly.');

In addition to #36, assertFileNotExists() and assertFileNotExists() are more appropriate here.

jungle’s picture

vsujeetkumar’s picture

Assigned: Unassigned » vsujeetkumar
vsujeetkumar’s picture

Assigned: vsujeetkumar » Unassigned
Status: Needs work » Needs review
FileSize
2.9 KB
1.13 KB

Updated test changes, Patch created, Please review.

dww’s picture

  1. +++ b/core/modules/update/tests/src/Kernel/UpdateDeleteFileIfStaleTest.php
    @@ -27,6 +27,21 @@ public function testUpdateDeleteFileIfStale() {
    +    // Test return status $deleted is consistent.
    

    Should remove this comment.

  2. +++ b/core/modules/update/tests/src/Kernel/UpdateDeleteFileIfStaleTest.php
    @@ -27,6 +27,21 @@ public function testUpdateDeleteFileIfStale() {
    +    $this->assertFalse($deleted, 'Stale file deletion reports failure correctly.');
    

    phpunit assertion messages should explain when the assertion fails. (Messages used to be positive in the SimpleTest world, but are negative now).

  3. +++ b/core/modules/update/tests/src/Kernel/UpdateDeleteFileIfStaleTest.php
    @@ -36,10 +51,12 @@ public function testUpdateDeleteFileIfStale() {
    +    // As before, test return status $deleted is consistent.
    

    Remove this.

  4. +++ b/core/modules/update/tests/src/Kernel/UpdateDeleteFileIfStaleTest.php
    @@ -36,10 +51,12 @@ public function testUpdateDeleteFileIfStale() {
    +    $this->assertTrue($deleted, 'Stale file deletion reports success correctly.');
    

    Fix this (see above).

  5. +++ b/core/modules/update/update.module
    @@ -832,6 +832,10 @@ function update_clear_update_disk_cache() {
    + *
    

    https://www.drupal.org/pift-ci-job/1664921

    /var/lib/drupalci/workspace/jenkins-drupal_patches-43446/source/core/modules/update/update.module ✗ 1 more
    line 839 Additional blank lines found at end of doc comment

Attached fixes all of this. But still NW for the change record. ;)

dww’s picture

Status: Needs work » Needs review
Issue tags: -Needs change record

Added the draft CR:

https://www.drupal.org/node/3131432

Needs version / branch info filled in when published, depending on how far back this gets backported.

RTBC?

Thanks
-Derek

dww’s picture

FileSize
2.79 KB
490 bytes

Slightly improved the @return docs (IMHO). ;) Canceled the testbot run on #41. Let's use this, instead.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

dww’s picture

Issue tags: +Bug Smash Initiative
FileSize
2.69 KB
2.44 KB

Self-review. Attached fixes all this:

  1. +++ b/core/modules/update/tests/src/Kernel/UpdateDeleteFileIfStaleTest.php
    @@ -27,6 +27,20 @@ public function testUpdateDeleteFileIfStale() {
    +    // During testing the file change and the stale checking occurs in the same
    

    Wants , after "During testing".

  2. +++ b/core/modules/update/tests/src/Kernel/UpdateDeleteFileIfStaleTest.php
    @@ -27,6 +27,20 @@ public function testUpdateDeleteFileIfStale() {
    +    $this->assertFalse($deleted, 'Non-stale file deletion should report failure.');
    

    A) Should come right after we get the value for $deleted.

    B) We don't need the assertion message here at all. It's obvious from the comments, and we're trying to get rid of those.

  3. +++ b/core/modules/update/tests/src/Kernel/UpdateDeleteFileIfStaleTest.php
    @@ -36,10 +50,11 @@ public function testUpdateDeleteFileIfStale() {
    +    // Now attempt to delete the file; as it should be considered stale,
    +    // this attempt should succeed.
    

    80 char wrapping is off.

  4. +++ b/core/modules/update/tests/src/Kernel/UpdateDeleteFileIfStaleTest.php
    @@ -36,10 +50,11 @@ public function testUpdateDeleteFileIfStale() {
    +    $this->assertTrue($deleted, 'Stale file deletion should report success.');
    

    Same as above:
    - Move directly under update_delete_file_if_stale() call.
    - Remove message.

dww’s picture

FileSize
3.47 KB
2.69 KB

Sorry, forgot test-only + full. This should be red/green candy.

jungle’s picture

Thanks @dww.

  1. +++ b/core/modules/update/tests/src/Kernel/UpdateDeleteFileIfStaleTest.php
    @@ -27,6 +27,20 @@ public function testUpdateDeleteFileIfStale() {
    +    // During testing, the file change and the stale checking occurs in the same
    +    // request, so the beginning of request will be before the file changes and
    +    // REQUEST_TIME - $filectime is negative or zero. Set the maximum age to a
    +    // number greater than that.
    ...
         // During testing the file change and the stale checking occurs in the same
         // request, so the beginning of request will be before the file changes and
    

    2 ~ 3 lines are duplicate, should the comments be reworded/adjusted?

  2. +++ b/core/modules/update/update.module
    @@ -710,10 +713,13 @@ function update_delete_file_if_stale($path) {
         if (REQUEST_TIME - $filectime > $max_age || (preg_match('/.*-dev\.(tar\.gz|zip)/i', $path) && REQUEST_TIME - $filectime > 300)) {
    

    Not sure the following are in scope:

    1. Replace REQUEST_TIME with \Drupal::time()->getRequestTime()?
    2. $filectime -> $file_ctime ?

Otherwise, it's good to me.

dww’s picture

@jungle: Thanks for the review! Re: #47:

1. Yeah, probably a good move. Fixed here. How's this?

2.1: IMHO, out of scope. That should be handled (everywhere) when core properly deprecates REQUEST_TIME.

2.2: Nope, we're referring to the value returned by filectime(). But to clarify, changing from $filectime to filectime(). ;)

Re: #46: I missed in drupalci.yml, this test-only should properly fail...

RTBC? 🤞

jungle’s picture

Status: Needs review » Reviewed & tested by the community
    $filectime = filectime($path);
    $max_age = \Drupal::config('system.file')->get('temporary_maximum_age');

    if (REQUEST_TIME - $filectime > $max_age || (preg_match('/.*-dev\.(tar\.gz|zip)/i', $path) && REQUEST_TIME - $filectime > 300)) {
    

To make it clear. I meant changing $filectime = filectime($path); to $file_ctime = filectime($path);, agree on that both 47.2.1 and 47.2.2 are out of scope.

The change looks good. #46 passed, #48 should pass too. So setting to RTBC. Thanks @dww!

dww’s picture

Re: #49: Oh, sorry, I totally missed the context you were quoting in #47.2. Whoops. But yeah, same answer. ;) Still out of scope.

Thanks for the review and RTBC!

Cheers,
-Derek

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed f96378a and pushed to 9.1.x. Thanks!

  • alexpott committed f96378a on 9.1.x
    Issue #2303323 by dww, quietone, tadityar, iyyappan.govind, vsujeetkumar...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.