1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-30 10:42:41 +01:00

Implicitly detect directories when updating a fragment from a ZIP

Summary: This fixes the update-from-ZIP functionality so that it will automatically detect directories in the ZIP that do not have explicit entries.  Some ZIP programs do not create directory entries explicitly, so if we fail to do this then there's no way for users to access the sub-fragments (even though they exist, there is no directory fragment to click through).

Test Plan: Created and updated fragments from a ZIP that had implicit directories in it.

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley

CC: Korvin, epriestley, aran, staticshock

Maniphest Tasks: T4205

Differential Revision: https://secure.phabricator.com/D7733
This commit is contained in:
James Rhodes 2013-12-08 12:10:00 +11:00
parent 7a5c3cc854
commit 5728ef7836

View file

@ -162,6 +162,33 @@ final class PhragmentFragment extends PhragmentDAO
$mappings[$path] = $data; $mappings[$path] = $data;
} }
// We need to detect any directories that are in the ZIP folder that
// aren't explicitly noted in the ZIP. This can happen if the file
// entries in the ZIP look like:
//
// * something/blah.png
// * something/other.png
// * test.png
//
// Where there is no explicit "something/" entry.
foreach ($mappings as $path_key => $data) {
if ($data === null) {
continue;
}
$directory = dirname($path_key);
while ($directory !== ".") {
if (!array_key_exists($directory, $mappings)) {
$mappings[$directory] = null;
}
if (dirname($directory) === $directory) {
// dirname() will not reduce this directory any further; to
// prevent infinite loop we just break out here.
break;
}
$directory = dirname($directory);
}
}
// Adjust the paths relative to this fragment so we can look existing // Adjust the paths relative to this fragment so we can look existing
// fragments up in the DB. // fragments up in the DB.
$base_path = $this->getPath(); $base_path = $this->getPath();