nextcloud/workflow_script

Provide placeholder for absolute path

steini86 opened this issue · 1 comments

All my scripts work with absolute paths and I use something like /var/www/m.js86.de/files/ocdata/"$1" where the first parameter is %n. However, it should be easy to directly provide a placeholder with the absolute path. (If I understand it correctly, %n is created by using the full path and stripping the base).

(If I understand it correctly, %n is created by using the full path and stripping the base)

nope, it's more complicated:

protected function replacePlaceholderN(Node $node): string {
$owner = $node->getOwner();
try {
$nodeID = $node->getId();
$storage = $node->getStorage();
} catch (NotFoundException | InvalidPathException $e) {
$context = [
'app' => 'workflow_script',
'exception' => $e,
'node' => $node,
];
$message = 'Could not get if of node {node}';
if (isset($nodeID)) {
$message = 'Could not find storage for file ID {fid}, node: {node}';
$context['fid'] = $nodeID;
}
$this->logger->warning($message, $context);
throw new PlaceholderNotSubstituted('n', $e);
}
if (isset($storage) && $storage->instanceOfStorage(GroupFolderStorage::class)) {
// group folders are always located within $DATADIR/__groupfolders/
$absPath = $storage->getLocalFile($node->getPath());
$pos = strpos($absPath, '/__groupfolders/');
// if the string cannot be found, the fallback is absolute path
// it should never happen #famousLastWords
if ($pos === false) {
$this->logger->warning(
'Groupfolder path does not contain __groupfolders. File ID: {fid}, Node path: {path}, absolute path: {abspath}',
[
'app' => 'workflow_script',
'fid' => $nodeID,
'path' => $node->getPath(),
'abspath' => $absPath,
]
);
}
$ncRelPath = substr($absPath, (int)$pos);
} elseif (isset($storage) && $storage->instanceOfStorage(SharedStorage::class)) {
try {
$folder = $this->rootFolder->getUserFolder($owner->getUID());
} catch (NotPermittedException | NoUserException $e) {
throw new PlaceholderNotSubstituted('n', $e);
}
$nodes = $folder->getById($nodeID);
if (empty($nodes)) {
throw new PlaceholderNotSubstituted('n');
}
$newNode = array_shift($nodes);
$ncRelPath = $newNode->getPath();
} else {
$ncRelPath = $node->getPath();
if (strpos($node->getPath(), $owner->getUID()) !== 0) {
$nodes = $this->rootFolder->getById($nodeID);
foreach ($nodes as $testNode) {
if (strpos($node->getPath(), $owner->getUID()) === 0) {
$ncRelPath = $testNode;
break;
}
}
}
}
$ncRelPath = ltrim($ncRelPath, '/');
return $ncRelPath;
}

%f should give you the absolute path for files available on local storage. Those from external will be copied to a temp directory.