Skip to content
This repository was archived by the owner on Nov 25, 2020. It is now read-only.

Commit f4de5d8

Browse files
committed
Set metastore files hidden if possible. Should fix #1077
1 parent 2a81ee7 commit f4de5d8

File tree

2 files changed

+22
-45
lines changed

2 files changed

+22
-45
lines changed

core/src/plugins/metastore.serial/SerialMetaStore.php

Lines changed: 22 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,14 @@
2020
*/
2121
namespace Pydio\Access\Metastore\Implementation;
2222

23+
use Pydio\Access\Core\MetaStreamWrapper;
2324
use Pydio\Access\Core\Model\AJXP_Node;
2425
use Pydio\Core\Controller\Controller;
2526
use Pydio\Access\Meta\Core\AbstractMetaSource;
2627
use Pydio\Access\Metastore\Core\IMetaStoreProvider;
28+
use Pydio\Core\Utils\TextEncoder;
29+
use Pydio\Core\Utils\Vars\PathUtils;
30+
use Pydio\Core\Utils\Vars\StatHelper;
2731

2832
defined('AJXP_EXEC') or die( 'Access not allowed');
2933
/**
@@ -103,6 +107,7 @@ public function setMetadata($ajxpNode, $nameSpace, $metaData, $private = false,
103107
* @param String $nameSpace
104108
* @param bool $private
105109
* @param int $scope
110+
* @return array|void
106111
*/
107112
public function removeMetadata($ajxpNode, $nameSpace, $private = false, $scope=AJXP_METADATA_SCOPE_REPOSITORY)
108113
{
@@ -312,10 +317,22 @@ protected function saveMetaFileData($ajxpNode, $scope, $userId)
312317
unset(self::$fullMetaCache[$metaFile][$fileKey]);
313318
}
314319
}
315-
$fp = @fopen($metaFile, "w");
320+
$writeMode = "w";
321+
$nodeIsWinLocal = false;
322+
if($scope === AJXP_METADATA_SCOPE_GLOBAL && $this->nodeIsLocalWindowsFS($ajxpNode) && file_exists($metaFile)){
323+
$nodeIsWinLocal = true;
324+
$writeMode = "rw+";
325+
}
326+
$fp = @fopen($metaFile, $writeMode);
316327
if ($fp !== false) {
317328
@fwrite($fp, serialize(self::$fullMetaCache[$metaFile]), strlen(serialize(self::$fullMetaCache[$metaFile])));
318329
@fclose($fp);
330+
if($nodeIsWinLocal){
331+
$real_path_metafile = TextEncoder::toStorageEncoding(realpath(MetaStreamWrapper::getRealFSReference($metaFile)));
332+
if (is_dir(dirname($real_path_metafile))) {
333+
StatHelper::winSetHidden($real_path_metafile);
334+
}
335+
}
319336
}else{
320337
$this->logError(__FUNCTION__, "Error while trying to open the meta file, maybe a permission problem?");
321338
}
@@ -360,44 +377,11 @@ public function collectChildrenWithRepositoryMeta($ajxpNode, $nameSpace, $userSc
360377
}
361378

362379
/**
363-
* @param \Pydio\Access\Core\Model\AJXP_Node|null $srcNode
364-
* @param \Pydio\Access\Core\Model\AJXP_Node|null $destNode
365-
* @param bool|false $copy
380+
* @param AJXP_Node $ajxpNode
381+
* @return bool
366382
*/
367-
public function nodeChangeHook($srcNode = null, $destNode = null, $copy = false){
368-
// This is not called, it's the responsibility of the meta provider/setter to
369-
// handle the node.change event.
370-
// For example, it would break the ShareCenter "shares" management.
371-
/*
372-
if($srcNode == null || $copy) return;
373-
$operation = $destNode == null ? "delete" : "move";
374-
$repositoryId = $srcNode->getRepositoryId();
375-
$metaFile = $this->globalMetaFile."_".$repositoryId;
376-
$metaFile = $this->updateSecurityScope($metaFile, $srcNode->getRepositoryId(), $srcNode->getUser());
377-
if(!is_file($metaFile)) return;
378-
$raw_data = file_get_contents($metaFile);
379-
if($raw_data === false) return;
380-
$metadata = unserialize($raw_data);
381-
if($metadata === false || !is_array($metadata)) return;
382-
$changes = false;
383-
$srcPath = $srcNode->getPath();
384-
foreach($metadata as $path => $data){
385-
preg_match("#^".preg_quote($srcPath, "#")."/#", $path, $matches);
386-
if($path == $srcPath || count($matches)){
387-
if($operation == "move"){
388-
if($path == $srcPath) $newPath = $destNode->getPath();
389-
else $newPath = preg_replace("#^".preg_quote($srcPath, "#")."#", $destNode->getPath(), $path);
390-
$metadata[$newPath] = $data;
391-
}
392-
unset($metadata[$path]);
393-
$changes = true;
394-
}
395-
}
396-
if($changes){
397-
// Should update $metadata now.
398-
@file_put_contents($metaFile, serialize($metadata));
399-
}
400-
*/
383+
private function nodeIsLocalWindowsFS($ajxpNode){
384+
return (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN' && !MetaStreamWrapper::wrapperIsRemote($ajxpNode->getUrl()));
401385
}
402386

403387
/**

core/src/plugins/metastore.serial/manifest.xml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,4 @@
1010
<param name="METADATA_FILE_LOCATION" type="select" choices="infolders|CONF_MESSAGE[In Local Folders],outside|CONF_MESSAGE[Application Data Folder]" label="CONF_MESSAGE[File location]" description="CONF_MESSAGE[Where to store the metadata file : LOCAL means a hidden file will be created in each folder, GLOBAL means that one file will be created in AJXP_DATA_PATH/plugins/action.share folder.]" mandatory="true" default="infolders"/>
1111
<param name="METADATA_FILE" type="string" label="CONF_MESSAGE[Meta File]" description="CONF_MESSAGE[Hidden file used inside folders to save meta data]" mandatory="true" default=".ajxp_meta"/>
1212
</server_settings>
13-
<registry_contributions>
14-
<!--
15-
<hooks>
16-
<serverCallback hookName="node.change" methodName="nodeChangeHook"/>
17-
</hooks>
18-
-->
19-
</registry_contributions>
2013
</metastore>

0 commit comments

Comments
 (0)