]> source.dussan.org Git - nextcloud-server.git/commitdiff
Fixed SMB file deletion success detection
authorVincent Petry <pvince81@owncloud.com>
Thu, 14 Nov 2013 17:39:39 +0000 (18:39 +0100)
committerVincent Petry <pvince81@owncloud.com>
Tue, 19 Nov 2013 14:05:11 +0000 (15:05 +0100)
Since unlink() smb4php doesn't return true on deletion success, we need
to check whether the file was deleted to confirm success.

Fixes #5866

apps/files_external/lib/smb.php
tests/lib/files/storage/storage.php

index c464fa9107a79e59ff8b30b26dedc11aec9cc99e..5bff597fdca0607a9aeff09c9eae4f9575d39ed7 100644 (file)
@@ -81,6 +81,18 @@ class SMB extends \OC\Files\Storage\StreamWrapper{
                }
        }
 
+       /**
+        * Unlinks file
+        * @param string @path
+        */
+       public function unlink($path) {
+               unlink($this->constructUrl($path));
+               clearstatcache();
+               // smb4php still returns false even on success so
+               // check here whether file was really deleted
+               return !file_exists($path);
+       }
+
        /**
         * check if a file or folder has been updated since $time
         * @param string $path
index f72a5276db51180863dd60603b3f403f8d2411b2..6c433e95475c7c8ecdd21af266569bccfd409560 100644 (file)
@@ -182,8 +182,9 @@ abstract class Storage extends \PHPUnit_Framework_TestCase {
                $this->assertTrue($this->instance->hasUpdated('/lorem.txt', $ctimeStart - 5));
                $this->assertTrue($this->instance->hasUpdated('/', $ctimeStart - 5));
 
-               $this->assertTrue(($ctimeStart - 5) <= $mTime);
-               $this->assertTrue($mTime <= ($ctimeEnd + 1));
+               // check that ($ctimeStart - 5) <= $mTime <= ($ctimeEnd + 1)
+               $this->assertGreaterThanOrEqual(($ctimeStart - 5), $mTime);
+               $this->assertLessThanOrEqual(($ctimeEnd + 1), $mTime);
                $this->assertEquals(filesize($textFile), $this->instance->filesize('/lorem.txt'));
 
                $stat = $this->instance->stat('/lorem.txt');
@@ -202,6 +203,17 @@ abstract class Storage extends \PHPUnit_Framework_TestCase {
                $this->assertTrue($this->instance->hasUpdated('/', $mtimeStart - 5));
        }
 
+       public function testUnlink() {
+               $textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt';
+               $this->instance->file_put_contents('/lorem.txt', file_get_contents($textFile));
+
+               $this->assertTrue($this->instance->file_exists('/lorem.txt'));
+
+               $this->assertTrue($this->instance->unlink('/lorem.txt'));
+
+               $this->assertFalse($this->instance->file_exists('/lorem.txt'));
+       }
+
        public function testFOpen() {
                $textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt';