Problem/Motivation

Deprecated function: filectime(): Passing null to parameter #1 ($filename) of type string is deprecated in Drupal\backup_migrate\Core\File\ReadableStreamBackupFile->loadFileStats() (line 196 of C:\xampp\htdocs\*\web\modules\contrib\backup_migrate\src\Core\File\ReadableStreamBackupFile.php)

Deprecated function: filesize(): Passing null to parameter #1 ($filename) of type string is deprecated in Drupal\backup_migrate\Core\File\ReadableStreamBackupFile->loadFileStats() (line 195 of C:\xampp\htdocs\*\web\modules\contrib\backup_migrate\src\Core\File\ReadableStreamBackupFile.php)

Steps to reproduce

php8.1

Comments

crutch created an issue. See original summary.

mok7tar’s picture

StatusFileSize
new3.77 KB

this patch for backup_migrate": "^5.0" stable version

damienmckenna’s picture

Title: Deprecated functions - filectime() and filesize() » filectime() and filesize() receiving NULL values
Status: Active » Needs review

Thank you for the patch.

I suspect there might be a different problem. Why are the files being passed to filectime() and filesize() coming back with NULL values?

damienmckenna’s picture

Status: Needs review » Needs work
mok7tar’s picture

@damienMcKenna
on
src/Core/File/ReadableStreamBackupFile.php Line 60

public function realpath() {
if (file_exists($this->path)) {
return $this->path;
}
return NULL;
}

realpath return null if file not exist on input path

mok7tar’s picture

StatusFileSize
new1.18 KB

So we can replace this patch with centralized solution for rela path method

damienmckenna’s picture

I think they should throw an exception if the file can't be found instead of just returning some sort of an empty string.

mok7tar’s picture

yes i think it will be better

donpwinston’s picture

These two patches do not fix the problem. The filename should not be empty. I get the following:

#0 /var/www/html/core/includes/bootstrap.inc(346): _drupal_error_handler_real()
#1 [internal function]: _drupal_error_handler()
#2 /var/www/html/modules/contrib/backup_migrate/src/Core/File/ReadableStreamBackupFile.php(196): filectime()
#3 /var/www/html/modules/contrib/backup_migrate/src/Core/File/WritableStreamBackupFile.php(82): Drupal\backup_migrate\Core\File\ReadableStreamBackupFile->loadFileStats()
#4 /var/www/html/modules/contrib/backup_migrate/src/Core/File/ReadableStreamBackupFile.php(51): Drupal\backup_migrate\Core\File\WritableStreamBackupFile->close()
#5 /var/www/html/modules/contrib/backup_migrate/src/Core/Destination/DirectoryDestination.php(26): Drupal\backup_migrate\Core\File\ReadableStreamBackupFile->__destruct()
...

I think closing the file and/or the __destruct method is blowing away the path property before loadFileSats() is called. In the close() method maybe parent::close() should be at the end?

/**
   * Update the file time and size when the file is closed.
   */
  public function close() {
    parent::close();

    // If the file has been modified, update the stats from disk.
    if ($this->dirty) {
      $this->loadFileStats();
      $this->dirty = FALSE;
    }
  }

Nope. Tried that and it and still got error. I do not know why the $path is null.

Christopher Riley’s picture

the latest patch doesn't work via composer patches when the root directory is not web. I pulled the patch and manually ran the patch routine pointing it to the correct directory and seems to have resolved the issue.

robcarr’s picture

Version: 5.0.x-dev » 5.1.x-dev
StatusFileSize
new643 bytes

Recent patches wouldn't apply to 5.0.x nor 5.1.x. Have re-rolled the palliative patch that returns an empty (rather than a NULL) value to avoid the deprecation error. Changed to 5.1.x branch

crutch’s picture

#11 applies and removes deprecated function warnings. Not seeing issues as described in #9.

damienmckenna’s picture

Priority: Minor » Normal

This is showing up when tests are ran on D10, so it has bumped in importance a little.

damienmckenna’s picture

This affects both the 5.0.x and 5.1.x branches.

ericdsd’s picture

Patch #11 applied on 5.0.2, works like a charm.
@donpwinston I didn't get how to reproduce issue mentioned in #10,could you explain the steps to reproduce ?

damienmckenna’s picture

Status: Needs work » Needs review
StatusFileSize
new654 bytes

After some looking I found that the problem was simpler than this - in ReadableStreamBackupFile::loadFileStats() it shouldn't be trying to get meta data if the file doesn't exist.

solideogloria’s picture

In ReadableStreamBackupFile.php, it still should probably have return type of string|null if it's going to return NULL sometimes.

damienmckenna’s picture

StatusFileSize
new2.12 KB

Good point!

solideogloria’s picture

Sorry, one more nitpick I noticed. BackupFileWritableInterface extends BackupFileReadableInterface, so it doesn't need to have its own public function realpath();, unless I'm mistaken.

  • DamienMcKenna committed 6dc1fef on 5.0.x
    Issue #3268401 by DamienMcKenna, Mok7tar, robcarr, crutch, solideogloria...
damienmckenna’s picture

Status: Needs review » Fixed

Yes, you are correct.

Committed, minus the duplicated code in BackupFileWritableInterface.

Thanks everyone!

solideogloria’s picture

Thank you!

  • DamienMcKenna committed 6538f84 on 5.1.x
    Issue #3268401 by DamienMcKenna, Mok7tar, robcarr, crutch, solideogloria...

Status: Fixed » Closed (fixed)

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