Work around issue where 'allinfo' keeps the file open

This commit is contained in:
Robin Appelman 2015-02-10 17:37:37 +01:00
commit ededbfbaa3
5 changed files with 57 additions and 6 deletions

View file

@ -11,6 +11,7 @@ use Icewind\SMB\Exception\AccessDeniedException;
use Icewind\SMB\Exception\AlreadyExistsException;
use Icewind\SMB\Exception\ConnectionException;
use Icewind\SMB\Exception\Exception;
use Icewind\SMB\Exception\FileInUseException;
use Icewind\SMB\Exception\InvalidTypeException;
use Icewind\SMB\Exception\NotEmptyException;
use Icewind\SMB\Exception\NotFoundException;
@ -70,6 +71,14 @@ class Share implements IShare {
}
}
protected function reconnect() {
$this->connection->reconnect();
$this->connection->writeAuthentication($this->server->getUser(), $this->server->getPassword());
if (!$this->connection->isValid()) {
throw new ConnectionException();
}
}
/**
* Get the name of the share
*
@ -150,12 +159,13 @@ class Share implements IShare {
* Delete a file on the share
*
* @param string $path
* @param bool $secondTry
* @return bool
*
* @throws \Icewind\SMB\Exception\NotFoundException
* @throws \Icewind\SMB\Exception\InvalidTypeException
* @throws InvalidTypeException
* @throws NotFoundException
* @throws \Exception
*/
public function del($path) {
public function del($path, $secondTry = false) {
//del return a file not found error when trying to delete a folder
//we catch it so we can check if $path doesn't exist or is of invalid type
try {
@ -170,6 +180,12 @@ class Share implements IShare {
throw new InvalidTypeException($path);
}
throw $e;
} catch (FileInUseException $e) {
if ($secondTry) {
throw $e;
}
$this->reconnect();
return $this->del($path, true);
}
}