From 980382457f8f6970231c17c45b31f181301502f0 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Wed, 21 Nov 2018 16:51:30 +0100 Subject: [PATCH] apply configured default filters --- admin.php | 31 ++++++++++++++++++++++++++----- conf/default.php | 2 +- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/admin.php b/admin.php index 32ccd87..9793119 100755 --- a/admin.php +++ b/admin.php @@ -10,10 +10,8 @@ */ class admin_plugin_backup extends DokuWiki_Admin_Plugin { - var $state = 0; - var $backup = ''; - protected $prefFile = DOKU_CONF . 'backup.json'; + protected $filters = null; /** @inheritdoc */ public function handle() @@ -231,13 +229,36 @@ protected function addDirectoryToTar(Tar $tar, $dir, $as, $logger = null, $filte // custom filter: if ($filter !== null && !$filter($file)) continue; - // default filter: - // FIXME $this->getConf('filterdirs'); + if (!$this->defaultFilter($file)) continue; if ($logger !== null) $logger($file); $tar->addFile($path, $file); } + } + + /** + * Checks the default filters against the given backup path + * + * We also filter .git directories + * + * @param string $path the backup path + * @return bool true if the file should be backed up, false if not + */ + protected function defaultFilter($path) + { + if ($this->filters === null) { + $this->filters = explode("\n", $this->getConf('filterdirs')); + $this->filters = array_map('trim', $this->filters); + $this->filters = array_filter($this->filters); + } + + if (strpos($path, '/.git') !== false) return false; + + foreach ($this->filters as $filter) { + if (strpos($path, $filter) === 0) return false; + } + return true; } /** diff --git a/conf/default.php b/conf/default.php index 8b2b004..470e14a 100644 --- a/conf/default.php +++ b/conf/default.php @@ -1,5 +1,5 @@