Skip to content

Commit

Permalink
Fixing deleting of crops that are directly in the crops_dir
Browse files Browse the repository at this point in the history
As opposed to in a subdir
Fixes #103
  • Loading branch information
weotch committed Jan 22, 2016
1 parent 27f57c4 commit 6e78aa5
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/Bkwld/Croppa/Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,16 +221,22 @@ public function tooManyCrops($path) {
* @return array
*/
public function listCrops($path) {
$src = basename($path);
return $this->justPaths(array_filter($this->crops_disk->listContents(dirname($path)),
function($file) use ($src) {

// Get the filename and dir
$filename = basename($path);
$dir = dirname($path);
if ($dir === '.') $dir = ''; // Flysystem doesn't like "." for the dir

// Filter the files in the dir to just crops of the image path
return $this->justPaths(array_filter($this->crops_disk->listContents($dir),
function($file) use ($filename) {

// Don't return the source image, we're JUST getting crops
return $file['basename'] != $src
return $file['basename'] != $filename

// Test that the crop begins with the src's path, that the crop is FOR
// the src
&& strpos($file['basename'], pathinfo($src, PATHINFO_FILENAME)) === 0
&& strpos($file['basename'], pathinfo($filename, PATHINFO_FILENAME)) === 0

// Make sure that the crop matches that Croppa file regex
&& preg_match('#'.URL::PATTERN.'#', $file['path']);
Expand Down

0 comments on commit 6e78aa5

Please sign in to comment.