Skip to content

Commit

Permalink
Merge pull request #139 from nextcloud/fix138
Browse files Browse the repository at this point in the history
Attempt to fix postWrite hook, fix #138
  • Loading branch information
Julien Veyssier committed Sep 15, 2019
2 parents 9a4edd7 + c06ad59 commit f546946
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
3 changes: 2 additions & 1 deletion appinfo/application.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ public function __construct (array $urlParams=array()) {
\OC::$server->query(PhotofilesService::class),
\OC::$server->query(TracksService::class),
$c->query('ServerContainer')->getLogger(),
$c->query('AppName')
$c->query('AppName'),
$c->query('ServerContainer')->getLockingProvider()
);
});

Expand Down
18 changes: 13 additions & 5 deletions lib/Hooks/FileHooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use OCP\ILogger;
use OCP\Files\Node;
use OCP\Files\IRootFolder;
use OCP\Lock\ILockingProvider;
use OCP\Util;
use OCP\Share;

Expand All @@ -36,19 +37,26 @@ class FileHooks {

private $root;

public function __construct(IRootFolder $root, PhotofilesService $photofilesService, TracksService $tracksService, ILogger $logger, $appName) {
public function __construct(IRootFolder $root, PhotofilesService $photofilesService, TracksService $tracksService,
ILogger $logger, $appName, ILockingProvider $lockingProvider) {
$this->photofilesService = $photofilesService;
$this->tracksService = $tracksService;
$this->logger = $logger;
$this->root = $root;
$this->lockingProvider = $lockingProvider;
}

public function register() {
$fileWriteCallback = function(\OCP\Files\Node $node) {
if ($this->isUserNode($node)) {
$isPhoto = $this->photofilesService->safeAddByFile($node);
if (!$isPhoto) {
$this->tracksService->safeAddByFile($node);
if ($this->isUserNode($node) && $node->getSize() > 0) {
$path = $node->getPath();
if (!$this->lockingProvider->isLocked($path, ILockingProvider::LOCK_SHARED)
and !$this->lockingProvider->isLocked($path, ILockingProvider::LOCK_EXCLUSIVE)
) {
$isPhoto = $this->photofilesService->safeAddByFile($node);
if (!$isPhoto) {
$this->tracksService->safeAddByFile($node);
}
}
}
};
Expand Down

0 comments on commit f546946

Please sign in to comment.