Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Not exact 3 files existent in folder" - wrong assumptions about file system #304

Closed
d--j opened this issue Sep 12, 2020 · 1 comment · Fixed by #306
Closed

"Not exact 3 files existent in folder" - wrong assumptions about file system #304

d--j opened this issue Sep 12, 2020 · 1 comment · Fixed by #306

Comments

@d--j
Copy link

d--j commented Sep 12, 2020

Trying to execute the updater I get

$ php updater.phar 
Nextcloud Updater - version: v16.0.3-3-ga0c2b25 dirty

Current version is 18.0.9.

Update to Nextcloud 19.0.3 available. (channel: "stable")
Following file will be downloaded automatically: https://download.nextcloud.com/server/releases/nextcloud-19.0.3.zip
Open changelog ↗

Steps that will be executed:
[ ] Check for expected files
[ ] Check for write permissions
[ ] Create backup
[ ] Downloading
[ ] Verify integrity
[ ] Extracting
[ ] Enable maintenance mode
[ ] Replace entry points
[ ] Delete old files
[ ] Move new files in place
[ ] Done

Start update? [y/N] y

Info: Pressing Ctrl-C will finish the currently running step and then stops the updater.

[✔] Check for expected files
[✔] Check for write permissions
[✔] Create backup
[✔] Downloading
[✘] Verify integrity failed
Not exact 3 files existent in folder

Update failed. To resume or retry just execute the updater again.

The error is thrown here:

updater/lib/Updater.php

Lines 576 to 586 in cbf2b53

private function getDownloadedFilePath() {
$storageLocation = $this->getDataDirectoryLocation() . '/updater-'.$this->getConfigOption('instanceid') . '/downloads/';
$this->silentLog('[info] storage location: ' . $storageLocation);
$files = scandir($storageLocation);
// ., .. and downloaded zip archive
if(count($files) !== 3) {
throw new \Exception('Not exact 3 files existent in folder');
}
return $storageLocation . '/' . $files[2];
}

updater/index.php

Lines 693 to 703 in cbf2b53

private function getDownloadedFilePath() {
$storageLocation = $this->getDataDirectoryLocation() . '/updater-'.$this->getConfigOption('instanceid') . '/downloads/';
$this->silentLog('[info] storage location: ' . $storageLocation);
$files = scandir($storageLocation);
// ., .. and downloaded zip archive
if(count($files) !== 3) {
throw new \Exception('Not exact 3 files existent in folder');
}
return $storageLocation . '/' . $files[2];
}

This function assumes that a scandir always includes . and .. (and that they are the first and second entry in a scandir). This assumption is wrong. The data folder of this particular Nextcloud installation is on a FUSE filesystem (more exactly, it's S3QL). This filesystem does not return . and .. in a scandir call. Also . and .. could be on different positions in the array, so unconditionally accessing the third entry is wrong, too.

Something like this should handle these cases:

 private function getDownloadedFilePath() { 
 	$storageLocation = $this->getDataDirectoryLocation() . '/updater-'.$this->getConfigOption('instanceid') . '/downloads/'; 
 	$this->silentLog('[info] storage location: ' . $storageLocation); 
  
 	$files = array_filter(scandir($storageLocation), function($path){ return $path != "." && $path != ".."; });
 	if(count($files) !== 1) { 
 		throw new \Exception('Not exactly 1 entry exists in folder'); 
 	} 
 	return $storageLocation . '/' . $files[0]; 
 } 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants