Skip to content

Commit

Permalink
#45 Fix Windows issues (#46)
Browse files Browse the repository at this point in the history
* #45 Removed files which cannot be checked out on Windows

* #45 Fixed command validator

* #45 Ensured BagUtils::getAbsolute() is stripping the drive part before splitting/joining paths and improved validation

* #45 Ensured Bag::internalPath() and related code that needs to have an "internal" path is using always the "/" as directory separator

* #45 Fixed issues with line wrapping

* #45 Fixed issue with extension recognition (e.g. filename.EXTRA.tar.gz fails)

* #45 Ensured Bag::makeAbsolute() and related places return paths using DIRECTORY_SEPARATOR

* #45 Formatting/reduced nesting

* #45 Updated tests that relied on unfriendly Windows filenames

* #45 Fixed tests on Windows due to line-break differences/directory separators

* #45 Removed not needed call

* #45 Fixed code sniffing issues
  • Loading branch information
jonasraoni authored Jun 23, 2022
1 parent 4489dc8 commit f2496ce
Show file tree
Hide file tree
Showing 18 changed files with 498 additions and 523 deletions.
69 changes: 35 additions & 34 deletions src/AbstractManifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,43 +209,44 @@ protected function loadFile(): void
$this->hashes = [];
$this->resetLoadIssues();
$fullPath = $this->bag->makeAbsolute($this->filename);
if (file_exists($fullPath)) {
$file_contents = file_get_contents($fullPath);
if ($file_contents === false) {
throw new FilesystemException("Unable to read file $fullPath");
if (!file_exists($fullPath)) {
return;
}
$file_contents = file_get_contents($fullPath);
if ($file_contents === false) {
throw new FilesystemException("Unable to read file $fullPath");
}
$lineCount = 0;
$lines = BagUtils::splitFileDataOnLineEndings($file_contents);
foreach ($lines as $line) {
$lineCount += 1;
$line = $this->bag->decodeText($line);
$line = trim($line);
if (empty($line)) {
continue;
}
$lineCount = 0;
$lines = BagUtils::splitFileDataOnLineEndings($file_contents);
foreach ($lines as $line) {
$lineCount += 1;
$line = $this->bag->decodeText($line);
$line = trim($line);
if (empty($line)) {
continue;
}
if (preg_match("~^(\w+)\s+\*?(.*)$~", $line, $matches)) {
$hash = $matches[1];
$originalPath = $matches[2];
$this->checkIncomingFilePath($originalPath, $lineCount);
$path = $this->cleanUpRelPath($originalPath);
// Normalized path in lowercase (for matching)
$lowerNormalized = $this->normalizePath($path);
if (array_key_exists($path, $this->hashes)) {
$this->addLoadError("Line $lineCount: Path $originalPath appears more than once in " .
"manifest.");
} elseif ($this->matchNormalizedList($lowerNormalized)) {
$this->addLoadWarning("Line $lineCount: Path $originalPath matches another file when " .
"normalized for case and characters.");
} elseif (empty($path)) {
$this->addLoadError("Line $lineCount: Path $originalPath resolves to a path outside of the " .
"data/ directory.");
} else {
$this->hashes[$path] = $hash;
$this->addToNormalizedList($lowerNormalized);
}
if (preg_match("~^(\w+)\s+\*?(.*)$~", $line, $matches)) {
$hash = $matches[1];
$originalPath = $matches[2];
$this->checkIncomingFilePath($originalPath, $lineCount);
$path = $this->cleanUpRelPath($originalPath);
// Normalized path in lowercase (for matching)
$lowerNormalized = $this->normalizePath($path);
if (array_key_exists($path, $this->hashes)) {
$this->addLoadError("Line $lineCount: Path $originalPath appears more than once in " .
"manifest.");
} elseif ($this->matchNormalizedList($lowerNormalized)) {
$this->addLoadWarning("Line $lineCount: Path $originalPath matches another file when " .
"normalized for case and characters.");
} elseif (empty($path)) {
$this->addLoadError("Line $lineCount: Path $originalPath resolves to a path outside of the " .
"data/ directory.");
} else {
$this->addLoadError("Line $lineCount: Line is not of the form 'checksum path'");
$this->hashes[$path] = $hash;
$this->addToNormalizedList($lowerNormalized);
}
} else {
$this->addLoadError("Line $lineCount: Line is not of the form 'checksum path'");
}
}
}
Expand Down
Loading

0 comments on commit f2496ce

Please sign in to comment.