@@ -34,93 +34,93 @@ |
||
34 | 34 | */ |
35 | 35 | class CredentialsManager implements ICredentialsManager { |
36 | 36 | |
37 | - const DB_TABLE = 'credentials'; |
|
37 | + const DB_TABLE = 'credentials'; |
|
38 | 38 | |
39 | - /** @var ICrypto */ |
|
40 | - protected $crypto; |
|
39 | + /** @var ICrypto */ |
|
40 | + protected $crypto; |
|
41 | 41 | |
42 | - /** @var IDBConnection */ |
|
43 | - protected $dbConnection; |
|
42 | + /** @var IDBConnection */ |
|
43 | + protected $dbConnection; |
|
44 | 44 | |
45 | - /** |
|
46 | - * @param ICrypto $crypto |
|
47 | - * @param IDBConnection $dbConnection |
|
48 | - */ |
|
49 | - public function __construct(ICrypto $crypto, IDBConnection $dbConnection) { |
|
50 | - $this->crypto = $crypto; |
|
51 | - $this->dbConnection = $dbConnection; |
|
52 | - } |
|
45 | + /** |
|
46 | + * @param ICrypto $crypto |
|
47 | + * @param IDBConnection $dbConnection |
|
48 | + */ |
|
49 | + public function __construct(ICrypto $crypto, IDBConnection $dbConnection) { |
|
50 | + $this->crypto = $crypto; |
|
51 | + $this->dbConnection = $dbConnection; |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * Store a set of credentials |
|
56 | - * |
|
57 | - * @param string|null $userId Null for system-wide credentials |
|
58 | - * @param string $identifier |
|
59 | - * @param mixed $credentials |
|
60 | - */ |
|
61 | - public function store($userId, $identifier, $credentials) { |
|
62 | - $value = $this->crypto->encrypt(json_encode($credentials)); |
|
54 | + /** |
|
55 | + * Store a set of credentials |
|
56 | + * |
|
57 | + * @param string|null $userId Null for system-wide credentials |
|
58 | + * @param string $identifier |
|
59 | + * @param mixed $credentials |
|
60 | + */ |
|
61 | + public function store($userId, $identifier, $credentials) { |
|
62 | + $value = $this->crypto->encrypt(json_encode($credentials)); |
|
63 | 63 | |
64 | - $this->dbConnection->setValues(self::DB_TABLE, [ |
|
65 | - 'user' => $userId, |
|
66 | - 'identifier' => $identifier, |
|
67 | - ], [ |
|
68 | - 'credentials' => $value, |
|
69 | - ]); |
|
70 | - } |
|
64 | + $this->dbConnection->setValues(self::DB_TABLE, [ |
|
65 | + 'user' => $userId, |
|
66 | + 'identifier' => $identifier, |
|
67 | + ], [ |
|
68 | + 'credentials' => $value, |
|
69 | + ]); |
|
70 | + } |
|
71 | 71 | |
72 | - /** |
|
73 | - * Retrieve a set of credentials |
|
74 | - * |
|
75 | - * @param string|null $userId Null for system-wide credentials |
|
76 | - * @param string $identifier |
|
77 | - * @return mixed |
|
78 | - */ |
|
79 | - public function retrieve($userId, $identifier) { |
|
80 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
81 | - $qb->select('credentials') |
|
82 | - ->from(self::DB_TABLE) |
|
83 | - ->where($qb->expr()->eq('user', $qb->createNamedParameter($userId))) |
|
84 | - ->andWhere($qb->expr()->eq('identifier', $qb->createNamedParameter($identifier))) |
|
85 | - ; |
|
86 | - $result = $qb->execute()->fetch(); |
|
72 | + /** |
|
73 | + * Retrieve a set of credentials |
|
74 | + * |
|
75 | + * @param string|null $userId Null for system-wide credentials |
|
76 | + * @param string $identifier |
|
77 | + * @return mixed |
|
78 | + */ |
|
79 | + public function retrieve($userId, $identifier) { |
|
80 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
81 | + $qb->select('credentials') |
|
82 | + ->from(self::DB_TABLE) |
|
83 | + ->where($qb->expr()->eq('user', $qb->createNamedParameter($userId))) |
|
84 | + ->andWhere($qb->expr()->eq('identifier', $qb->createNamedParameter($identifier))) |
|
85 | + ; |
|
86 | + $result = $qb->execute()->fetch(); |
|
87 | 87 | |
88 | - if (!$result) { |
|
89 | - return null; |
|
90 | - } |
|
91 | - $value = $result['credentials']; |
|
88 | + if (!$result) { |
|
89 | + return null; |
|
90 | + } |
|
91 | + $value = $result['credentials']; |
|
92 | 92 | |
93 | - return json_decode($this->crypto->decrypt($value), true); |
|
94 | - } |
|
93 | + return json_decode($this->crypto->decrypt($value), true); |
|
94 | + } |
|
95 | 95 | |
96 | - /** |
|
97 | - * Delete a set of credentials |
|
98 | - * |
|
99 | - * @param string|null $userId Null for system-wide credentials |
|
100 | - * @param string $identifier |
|
101 | - * @return int rows removed |
|
102 | - */ |
|
103 | - public function delete($userId, $identifier) { |
|
104 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
105 | - $qb->delete(self::DB_TABLE) |
|
106 | - ->where($qb->expr()->eq('user', $qb->createNamedParameter($userId))) |
|
107 | - ->andWhere($qb->expr()->eq('identifier', $qb->createNamedParameter($identifier))) |
|
108 | - ; |
|
109 | - return $qb->execute(); |
|
110 | - } |
|
96 | + /** |
|
97 | + * Delete a set of credentials |
|
98 | + * |
|
99 | + * @param string|null $userId Null for system-wide credentials |
|
100 | + * @param string $identifier |
|
101 | + * @return int rows removed |
|
102 | + */ |
|
103 | + public function delete($userId, $identifier) { |
|
104 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
105 | + $qb->delete(self::DB_TABLE) |
|
106 | + ->where($qb->expr()->eq('user', $qb->createNamedParameter($userId))) |
|
107 | + ->andWhere($qb->expr()->eq('identifier', $qb->createNamedParameter($identifier))) |
|
108 | + ; |
|
109 | + return $qb->execute(); |
|
110 | + } |
|
111 | 111 | |
112 | - /** |
|
113 | - * Erase all credentials stored for a user |
|
114 | - * |
|
115 | - * @param string $userId |
|
116 | - * @return int rows removed |
|
117 | - */ |
|
118 | - public function erase($userId) { |
|
119 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
120 | - $qb->delete(self::DB_TABLE) |
|
121 | - ->where($qb->expr()->eq('user', $qb->createNamedParameter($userId))) |
|
122 | - ; |
|
123 | - return $qb->execute(); |
|
124 | - } |
|
112 | + /** |
|
113 | + * Erase all credentials stored for a user |
|
114 | + * |
|
115 | + * @param string $userId |
|
116 | + * @return int rows removed |
|
117 | + */ |
|
118 | + public function erase($userId) { |
|
119 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
120 | + $qb->delete(self::DB_TABLE) |
|
121 | + ->where($qb->expr()->eq('user', $qb->createNamedParameter($userId))) |
|
122 | + ; |
|
123 | + return $qb->execute(); |
|
124 | + } |
|
125 | 125 | |
126 | 126 | } |
@@ -27,104 +27,104 @@ |
||
27 | 27 | use OCP\ICertificate; |
28 | 28 | |
29 | 29 | class Certificate implements ICertificate { |
30 | - protected $name; |
|
31 | - |
|
32 | - protected $commonName; |
|
33 | - |
|
34 | - protected $organization; |
|
35 | - |
|
36 | - protected $serial; |
|
37 | - |
|
38 | - protected $issueDate; |
|
39 | - |
|
40 | - protected $expireDate; |
|
41 | - |
|
42 | - protected $issuerName; |
|
43 | - |
|
44 | - protected $issuerOrganization; |
|
45 | - |
|
46 | - /** |
|
47 | - * @param string $data base64 encoded certificate |
|
48 | - * @param string $name |
|
49 | - * @throws \Exception If the certificate could not get parsed |
|
50 | - */ |
|
51 | - public function __construct($data, $name) { |
|
52 | - $this->name = $name; |
|
53 | - $gmt = new \DateTimeZone('GMT'); |
|
54 | - |
|
55 | - // If string starts with "file://" ignore the certificate |
|
56 | - $query = 'file://'; |
|
57 | - if(strtolower(substr($data, 0, strlen($query))) === $query) { |
|
58 | - throw new \Exception('Certificate could not get parsed.'); |
|
59 | - } |
|
60 | - |
|
61 | - $info = openssl_x509_parse($data); |
|
62 | - if(!is_array($info)) { |
|
63 | - throw new \Exception('Certificate could not get parsed.'); |
|
64 | - } |
|
65 | - |
|
66 | - $this->commonName = isset($info['subject']['CN']) ? $info['subject']['CN'] : null; |
|
67 | - $this->organization = isset($info['subject']['O']) ? $info['subject']['O'] : null; |
|
68 | - $this->issueDate = new \DateTime('@' . $info['validFrom_time_t'], $gmt); |
|
69 | - $this->expireDate = new \DateTime('@' . $info['validTo_time_t'], $gmt); |
|
70 | - $this->issuerName = isset($info['issuer']['CN']) ? $info['issuer']['CN'] : null; |
|
71 | - $this->issuerOrganization = isset($info['issuer']['O']) ? $info['issuer']['O'] : null; |
|
72 | - } |
|
73 | - |
|
74 | - /** |
|
75 | - * @return string |
|
76 | - */ |
|
77 | - public function getName() { |
|
78 | - return $this->name; |
|
79 | - } |
|
80 | - |
|
81 | - /** |
|
82 | - * @return string|null |
|
83 | - */ |
|
84 | - public function getCommonName() { |
|
85 | - return $this->commonName; |
|
86 | - } |
|
87 | - |
|
88 | - /** |
|
89 | - * @return string |
|
90 | - */ |
|
91 | - public function getOrganization() { |
|
92 | - return $this->organization; |
|
93 | - } |
|
94 | - |
|
95 | - /** |
|
96 | - * @return \DateTime |
|
97 | - */ |
|
98 | - public function getIssueDate() { |
|
99 | - return $this->issueDate; |
|
100 | - } |
|
101 | - |
|
102 | - /** |
|
103 | - * @return \DateTime |
|
104 | - */ |
|
105 | - public function getExpireDate() { |
|
106 | - return $this->expireDate; |
|
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * @return bool |
|
111 | - */ |
|
112 | - public function isExpired() { |
|
113 | - $now = new \DateTime(); |
|
114 | - return $this->issueDate > $now or $now > $this->expireDate; |
|
115 | - } |
|
116 | - |
|
117 | - /** |
|
118 | - * @return string|null |
|
119 | - */ |
|
120 | - public function getIssuerName() { |
|
121 | - return $this->issuerName; |
|
122 | - } |
|
123 | - |
|
124 | - /** |
|
125 | - * @return string|null |
|
126 | - */ |
|
127 | - public function getIssuerOrganization() { |
|
128 | - return $this->issuerOrganization; |
|
129 | - } |
|
30 | + protected $name; |
|
31 | + |
|
32 | + protected $commonName; |
|
33 | + |
|
34 | + protected $organization; |
|
35 | + |
|
36 | + protected $serial; |
|
37 | + |
|
38 | + protected $issueDate; |
|
39 | + |
|
40 | + protected $expireDate; |
|
41 | + |
|
42 | + protected $issuerName; |
|
43 | + |
|
44 | + protected $issuerOrganization; |
|
45 | + |
|
46 | + /** |
|
47 | + * @param string $data base64 encoded certificate |
|
48 | + * @param string $name |
|
49 | + * @throws \Exception If the certificate could not get parsed |
|
50 | + */ |
|
51 | + public function __construct($data, $name) { |
|
52 | + $this->name = $name; |
|
53 | + $gmt = new \DateTimeZone('GMT'); |
|
54 | + |
|
55 | + // If string starts with "file://" ignore the certificate |
|
56 | + $query = 'file://'; |
|
57 | + if(strtolower(substr($data, 0, strlen($query))) === $query) { |
|
58 | + throw new \Exception('Certificate could not get parsed.'); |
|
59 | + } |
|
60 | + |
|
61 | + $info = openssl_x509_parse($data); |
|
62 | + if(!is_array($info)) { |
|
63 | + throw new \Exception('Certificate could not get parsed.'); |
|
64 | + } |
|
65 | + |
|
66 | + $this->commonName = isset($info['subject']['CN']) ? $info['subject']['CN'] : null; |
|
67 | + $this->organization = isset($info['subject']['O']) ? $info['subject']['O'] : null; |
|
68 | + $this->issueDate = new \DateTime('@' . $info['validFrom_time_t'], $gmt); |
|
69 | + $this->expireDate = new \DateTime('@' . $info['validTo_time_t'], $gmt); |
|
70 | + $this->issuerName = isset($info['issuer']['CN']) ? $info['issuer']['CN'] : null; |
|
71 | + $this->issuerOrganization = isset($info['issuer']['O']) ? $info['issuer']['O'] : null; |
|
72 | + } |
|
73 | + |
|
74 | + /** |
|
75 | + * @return string |
|
76 | + */ |
|
77 | + public function getName() { |
|
78 | + return $this->name; |
|
79 | + } |
|
80 | + |
|
81 | + /** |
|
82 | + * @return string|null |
|
83 | + */ |
|
84 | + public function getCommonName() { |
|
85 | + return $this->commonName; |
|
86 | + } |
|
87 | + |
|
88 | + /** |
|
89 | + * @return string |
|
90 | + */ |
|
91 | + public function getOrganization() { |
|
92 | + return $this->organization; |
|
93 | + } |
|
94 | + |
|
95 | + /** |
|
96 | + * @return \DateTime |
|
97 | + */ |
|
98 | + public function getIssueDate() { |
|
99 | + return $this->issueDate; |
|
100 | + } |
|
101 | + |
|
102 | + /** |
|
103 | + * @return \DateTime |
|
104 | + */ |
|
105 | + public function getExpireDate() { |
|
106 | + return $this->expireDate; |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * @return bool |
|
111 | + */ |
|
112 | + public function isExpired() { |
|
113 | + $now = new \DateTime(); |
|
114 | + return $this->issueDate > $now or $now > $this->expireDate; |
|
115 | + } |
|
116 | + |
|
117 | + /** |
|
118 | + * @return string|null |
|
119 | + */ |
|
120 | + public function getIssuerName() { |
|
121 | + return $this->issuerName; |
|
122 | + } |
|
123 | + |
|
124 | + /** |
|
125 | + * @return string|null |
|
126 | + */ |
|
127 | + public function getIssuerOrganization() { |
|
128 | + return $this->issuerOrganization; |
|
129 | + } |
|
130 | 130 | } |
@@ -54,19 +54,19 @@ |
||
54 | 54 | |
55 | 55 | // If string starts with "file://" ignore the certificate |
56 | 56 | $query = 'file://'; |
57 | - if(strtolower(substr($data, 0, strlen($query))) === $query) { |
|
57 | + if (strtolower(substr($data, 0, strlen($query))) === $query) { |
|
58 | 58 | throw new \Exception('Certificate could not get parsed.'); |
59 | 59 | } |
60 | 60 | |
61 | 61 | $info = openssl_x509_parse($data); |
62 | - if(!is_array($info)) { |
|
62 | + if (!is_array($info)) { |
|
63 | 63 | throw new \Exception('Certificate could not get parsed.'); |
64 | 64 | } |
65 | 65 | |
66 | 66 | $this->commonName = isset($info['subject']['CN']) ? $info['subject']['CN'] : null; |
67 | 67 | $this->organization = isset($info['subject']['O']) ? $info['subject']['O'] : null; |
68 | - $this->issueDate = new \DateTime('@' . $info['validFrom_time_t'], $gmt); |
|
69 | - $this->expireDate = new \DateTime('@' . $info['validTo_time_t'], $gmt); |
|
68 | + $this->issueDate = new \DateTime('@'.$info['validFrom_time_t'], $gmt); |
|
69 | + $this->expireDate = new \DateTime('@'.$info['validTo_time_t'], $gmt); |
|
70 | 70 | $this->issuerName = isset($info['issuer']['CN']) ? $info['issuer']['CN'] : null; |
71 | 71 | $this->issuerOrganization = isset($info['issuer']['O']) ? $info['issuer']['O'] : null; |
72 | 72 | } |
@@ -65,13 +65,13 @@ discard block |
||
65 | 65 | * @return string |
66 | 66 | */ |
67 | 67 | private function buildFileNameWithSuffix($absolutePath, $postFix = '') { |
68 | - if($postFix !== '') { |
|
69 | - $postFix = '.' . ltrim($postFix, '.'); |
|
68 | + if ($postFix !== '') { |
|
69 | + $postFix = '.'.ltrim($postFix, '.'); |
|
70 | 70 | $postFix = str_replace(['\\', '/'], '', $postFix); |
71 | 71 | $absolutePath .= '-'; |
72 | 72 | } |
73 | 73 | |
74 | - return $absolutePath . $postFix; |
|
74 | + return $absolutePath.$postFix; |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | /** |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | |
92 | 92 | // If a postfix got specified sanitize it and create a postfixed |
93 | 93 | // temporary file |
94 | - if($postFix !== '') { |
|
94 | + if ($postFix !== '') { |
|
95 | 95 | $fileNameWithPostfix = $this->buildFileNameWithSuffix($file, $postFix); |
96 | 96 | touch($fileNameWithPostfix); |
97 | 97 | chmod($fileNameWithPostfix, 0600); |
@@ -127,11 +127,11 @@ discard block |
||
127 | 127 | $this->current[] = $uniqueFileName; |
128 | 128 | |
129 | 129 | // Build a name without postfix |
130 | - $path = $this->buildFileNameWithSuffix($uniqueFileName . '-folder', $postFix); |
|
130 | + $path = $this->buildFileNameWithSuffix($uniqueFileName.'-folder', $postFix); |
|
131 | 131 | mkdir($path, 0700); |
132 | 132 | $this->current[] = $path; |
133 | 133 | |
134 | - return $path . '/'; |
|
134 | + return $path.'/'; |
|
135 | 135 | } else { |
136 | 136 | $this->log->warning( |
137 | 137 | 'Can not create a temporary folder in directory {dir}. Check it exists and has correct permissions', |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | if ($dh) { |
191 | 191 | while (($file = readdir($dh)) !== false) { |
192 | 192 | if (substr($file, 0, 7) === self::TMP_PREFIX) { |
193 | - $path = $this->tmpBaseDir . '/' . $file; |
|
193 | + $path = $this->tmpBaseDir.'/'.$file; |
|
194 | 194 | $mtime = filemtime($path); |
195 | 195 | if ($mtime < $cutOfTime) { |
196 | 196 | $files[] = $path; |
@@ -34,246 +34,246 @@ |
||
34 | 34 | use OCP\ITempManager; |
35 | 35 | |
36 | 36 | class TempManager implements ITempManager { |
37 | - /** @var string[] Current temporary files and folders, used for cleanup */ |
|
38 | - protected $current = []; |
|
39 | - /** @var string i.e. /tmp on linux systems */ |
|
40 | - protected $tmpBaseDir; |
|
41 | - /** @var ILogger */ |
|
42 | - protected $log; |
|
43 | - /** @var IConfig */ |
|
44 | - protected $config; |
|
37 | + /** @var string[] Current temporary files and folders, used for cleanup */ |
|
38 | + protected $current = []; |
|
39 | + /** @var string i.e. /tmp on linux systems */ |
|
40 | + protected $tmpBaseDir; |
|
41 | + /** @var ILogger */ |
|
42 | + protected $log; |
|
43 | + /** @var IConfig */ |
|
44 | + protected $config; |
|
45 | 45 | |
46 | - /** Prefix */ |
|
47 | - const TMP_PREFIX = 'oc_tmp_'; |
|
46 | + /** Prefix */ |
|
47 | + const TMP_PREFIX = 'oc_tmp_'; |
|
48 | 48 | |
49 | - /** |
|
50 | - * @param \OCP\ILogger $logger |
|
51 | - * @param \OCP\IConfig $config |
|
52 | - */ |
|
53 | - public function __construct(ILogger $logger, IConfig $config) { |
|
54 | - $this->log = $logger; |
|
55 | - $this->config = $config; |
|
56 | - $this->tmpBaseDir = $this->getTempBaseDir(); |
|
57 | - } |
|
49 | + /** |
|
50 | + * @param \OCP\ILogger $logger |
|
51 | + * @param \OCP\IConfig $config |
|
52 | + */ |
|
53 | + public function __construct(ILogger $logger, IConfig $config) { |
|
54 | + $this->log = $logger; |
|
55 | + $this->config = $config; |
|
56 | + $this->tmpBaseDir = $this->getTempBaseDir(); |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * Builds the filename with suffix and removes potential dangerous characters |
|
61 | - * such as directory separators. |
|
62 | - * |
|
63 | - * @param string $absolutePath Absolute path to the file / folder |
|
64 | - * @param string $postFix Postfix appended to the temporary file name, may be user controlled |
|
65 | - * @return string |
|
66 | - */ |
|
67 | - private function buildFileNameWithSuffix($absolutePath, $postFix = '') { |
|
68 | - if($postFix !== '') { |
|
69 | - $postFix = '.' . ltrim($postFix, '.'); |
|
70 | - $postFix = str_replace(['\\', '/'], '', $postFix); |
|
71 | - $absolutePath .= '-'; |
|
72 | - } |
|
59 | + /** |
|
60 | + * Builds the filename with suffix and removes potential dangerous characters |
|
61 | + * such as directory separators. |
|
62 | + * |
|
63 | + * @param string $absolutePath Absolute path to the file / folder |
|
64 | + * @param string $postFix Postfix appended to the temporary file name, may be user controlled |
|
65 | + * @return string |
|
66 | + */ |
|
67 | + private function buildFileNameWithSuffix($absolutePath, $postFix = '') { |
|
68 | + if($postFix !== '') { |
|
69 | + $postFix = '.' . ltrim($postFix, '.'); |
|
70 | + $postFix = str_replace(['\\', '/'], '', $postFix); |
|
71 | + $absolutePath .= '-'; |
|
72 | + } |
|
73 | 73 | |
74 | - return $absolutePath . $postFix; |
|
75 | - } |
|
74 | + return $absolutePath . $postFix; |
|
75 | + } |
|
76 | 76 | |
77 | - /** |
|
78 | - * Create a temporary file and return the path |
|
79 | - * |
|
80 | - * @param string $postFix Postfix appended to the temporary file name |
|
81 | - * @return string |
|
82 | - */ |
|
83 | - public function getTemporaryFile($postFix = '') { |
|
84 | - if (is_writable($this->tmpBaseDir)) { |
|
85 | - // To create an unique file and prevent the risk of race conditions |
|
86 | - // or duplicated temporary files by other means such as collisions |
|
87 | - // we need to create the file using `tempnam` and append a possible |
|
88 | - // postfix to it later |
|
89 | - $file = tempnam($this->tmpBaseDir, self::TMP_PREFIX); |
|
90 | - $this->current[] = $file; |
|
77 | + /** |
|
78 | + * Create a temporary file and return the path |
|
79 | + * |
|
80 | + * @param string $postFix Postfix appended to the temporary file name |
|
81 | + * @return string |
|
82 | + */ |
|
83 | + public function getTemporaryFile($postFix = '') { |
|
84 | + if (is_writable($this->tmpBaseDir)) { |
|
85 | + // To create an unique file and prevent the risk of race conditions |
|
86 | + // or duplicated temporary files by other means such as collisions |
|
87 | + // we need to create the file using `tempnam` and append a possible |
|
88 | + // postfix to it later |
|
89 | + $file = tempnam($this->tmpBaseDir, self::TMP_PREFIX); |
|
90 | + $this->current[] = $file; |
|
91 | 91 | |
92 | - // If a postfix got specified sanitize it and create a postfixed |
|
93 | - // temporary file |
|
94 | - if($postFix !== '') { |
|
95 | - $fileNameWithPostfix = $this->buildFileNameWithSuffix($file, $postFix); |
|
96 | - touch($fileNameWithPostfix); |
|
97 | - chmod($fileNameWithPostfix, 0600); |
|
98 | - $this->current[] = $fileNameWithPostfix; |
|
99 | - return $fileNameWithPostfix; |
|
100 | - } |
|
92 | + // If a postfix got specified sanitize it and create a postfixed |
|
93 | + // temporary file |
|
94 | + if($postFix !== '') { |
|
95 | + $fileNameWithPostfix = $this->buildFileNameWithSuffix($file, $postFix); |
|
96 | + touch($fileNameWithPostfix); |
|
97 | + chmod($fileNameWithPostfix, 0600); |
|
98 | + $this->current[] = $fileNameWithPostfix; |
|
99 | + return $fileNameWithPostfix; |
|
100 | + } |
|
101 | 101 | |
102 | - return $file; |
|
103 | - } else { |
|
104 | - $this->log->warning( |
|
105 | - 'Can not create a temporary file in directory {dir}. Check it exists and has correct permissions', |
|
106 | - [ |
|
107 | - 'dir' => $this->tmpBaseDir, |
|
108 | - ] |
|
109 | - ); |
|
110 | - return false; |
|
111 | - } |
|
112 | - } |
|
102 | + return $file; |
|
103 | + } else { |
|
104 | + $this->log->warning( |
|
105 | + 'Can not create a temporary file in directory {dir}. Check it exists and has correct permissions', |
|
106 | + [ |
|
107 | + 'dir' => $this->tmpBaseDir, |
|
108 | + ] |
|
109 | + ); |
|
110 | + return false; |
|
111 | + } |
|
112 | + } |
|
113 | 113 | |
114 | - /** |
|
115 | - * Create a temporary folder and return the path |
|
116 | - * |
|
117 | - * @param string $postFix Postfix appended to the temporary folder name |
|
118 | - * @return string |
|
119 | - */ |
|
120 | - public function getTemporaryFolder($postFix = '') { |
|
121 | - if (is_writable($this->tmpBaseDir)) { |
|
122 | - // To create an unique directory and prevent the risk of race conditions |
|
123 | - // or duplicated temporary files by other means such as collisions |
|
124 | - // we need to create the file using `tempnam` and append a possible |
|
125 | - // postfix to it later |
|
126 | - $uniqueFileName = tempnam($this->tmpBaseDir, self::TMP_PREFIX); |
|
127 | - $this->current[] = $uniqueFileName; |
|
114 | + /** |
|
115 | + * Create a temporary folder and return the path |
|
116 | + * |
|
117 | + * @param string $postFix Postfix appended to the temporary folder name |
|
118 | + * @return string |
|
119 | + */ |
|
120 | + public function getTemporaryFolder($postFix = '') { |
|
121 | + if (is_writable($this->tmpBaseDir)) { |
|
122 | + // To create an unique directory and prevent the risk of race conditions |
|
123 | + // or duplicated temporary files by other means such as collisions |
|
124 | + // we need to create the file using `tempnam` and append a possible |
|
125 | + // postfix to it later |
|
126 | + $uniqueFileName = tempnam($this->tmpBaseDir, self::TMP_PREFIX); |
|
127 | + $this->current[] = $uniqueFileName; |
|
128 | 128 | |
129 | - // Build a name without postfix |
|
130 | - $path = $this->buildFileNameWithSuffix($uniqueFileName . '-folder', $postFix); |
|
131 | - mkdir($path, 0700); |
|
132 | - $this->current[] = $path; |
|
129 | + // Build a name without postfix |
|
130 | + $path = $this->buildFileNameWithSuffix($uniqueFileName . '-folder', $postFix); |
|
131 | + mkdir($path, 0700); |
|
132 | + $this->current[] = $path; |
|
133 | 133 | |
134 | - return $path . '/'; |
|
135 | - } else { |
|
136 | - $this->log->warning( |
|
137 | - 'Can not create a temporary folder in directory {dir}. Check it exists and has correct permissions', |
|
138 | - [ |
|
139 | - 'dir' => $this->tmpBaseDir, |
|
140 | - ] |
|
141 | - ); |
|
142 | - return false; |
|
143 | - } |
|
144 | - } |
|
134 | + return $path . '/'; |
|
135 | + } else { |
|
136 | + $this->log->warning( |
|
137 | + 'Can not create a temporary folder in directory {dir}. Check it exists and has correct permissions', |
|
138 | + [ |
|
139 | + 'dir' => $this->tmpBaseDir, |
|
140 | + ] |
|
141 | + ); |
|
142 | + return false; |
|
143 | + } |
|
144 | + } |
|
145 | 145 | |
146 | - /** |
|
147 | - * Remove the temporary files and folders generated during this request |
|
148 | - */ |
|
149 | - public function clean() { |
|
150 | - $this->cleanFiles($this->current); |
|
151 | - } |
|
146 | + /** |
|
147 | + * Remove the temporary files and folders generated during this request |
|
148 | + */ |
|
149 | + public function clean() { |
|
150 | + $this->cleanFiles($this->current); |
|
151 | + } |
|
152 | 152 | |
153 | - /** |
|
154 | - * @param string[] $files |
|
155 | - */ |
|
156 | - protected function cleanFiles($files) { |
|
157 | - foreach ($files as $file) { |
|
158 | - if (file_exists($file)) { |
|
159 | - try { |
|
160 | - \OC_Helper::rmdirr($file); |
|
161 | - } catch (\UnexpectedValueException $ex) { |
|
162 | - $this->log->warning( |
|
163 | - "Error deleting temporary file/folder: {file} - Reason: {error}", |
|
164 | - [ |
|
165 | - 'file' => $file, |
|
166 | - 'error' => $ex->getMessage(), |
|
167 | - ] |
|
168 | - ); |
|
169 | - } |
|
170 | - } |
|
171 | - } |
|
172 | - } |
|
153 | + /** |
|
154 | + * @param string[] $files |
|
155 | + */ |
|
156 | + protected function cleanFiles($files) { |
|
157 | + foreach ($files as $file) { |
|
158 | + if (file_exists($file)) { |
|
159 | + try { |
|
160 | + \OC_Helper::rmdirr($file); |
|
161 | + } catch (\UnexpectedValueException $ex) { |
|
162 | + $this->log->warning( |
|
163 | + "Error deleting temporary file/folder: {file} - Reason: {error}", |
|
164 | + [ |
|
165 | + 'file' => $file, |
|
166 | + 'error' => $ex->getMessage(), |
|
167 | + ] |
|
168 | + ); |
|
169 | + } |
|
170 | + } |
|
171 | + } |
|
172 | + } |
|
173 | 173 | |
174 | - /** |
|
175 | - * Remove old temporary files and folders that were failed to be cleaned |
|
176 | - */ |
|
177 | - public function cleanOld() { |
|
178 | - $this->cleanFiles($this->getOldFiles()); |
|
179 | - } |
|
174 | + /** |
|
175 | + * Remove old temporary files and folders that were failed to be cleaned |
|
176 | + */ |
|
177 | + public function cleanOld() { |
|
178 | + $this->cleanFiles($this->getOldFiles()); |
|
179 | + } |
|
180 | 180 | |
181 | - /** |
|
182 | - * Get all temporary files and folders generated by oc older than an hour |
|
183 | - * |
|
184 | - * @return string[] |
|
185 | - */ |
|
186 | - protected function getOldFiles() { |
|
187 | - $cutOfTime = time() - 3600; |
|
188 | - $files = []; |
|
189 | - $dh = opendir($this->tmpBaseDir); |
|
190 | - if ($dh) { |
|
191 | - while (($file = readdir($dh)) !== false) { |
|
192 | - if (substr($file, 0, 7) === self::TMP_PREFIX) { |
|
193 | - $path = $this->tmpBaseDir . '/' . $file; |
|
194 | - $mtime = filemtime($path); |
|
195 | - if ($mtime < $cutOfTime) { |
|
196 | - $files[] = $path; |
|
197 | - } |
|
198 | - } |
|
199 | - } |
|
200 | - } |
|
201 | - return $files; |
|
202 | - } |
|
181 | + /** |
|
182 | + * Get all temporary files and folders generated by oc older than an hour |
|
183 | + * |
|
184 | + * @return string[] |
|
185 | + */ |
|
186 | + protected function getOldFiles() { |
|
187 | + $cutOfTime = time() - 3600; |
|
188 | + $files = []; |
|
189 | + $dh = opendir($this->tmpBaseDir); |
|
190 | + if ($dh) { |
|
191 | + while (($file = readdir($dh)) !== false) { |
|
192 | + if (substr($file, 0, 7) === self::TMP_PREFIX) { |
|
193 | + $path = $this->tmpBaseDir . '/' . $file; |
|
194 | + $mtime = filemtime($path); |
|
195 | + if ($mtime < $cutOfTime) { |
|
196 | + $files[] = $path; |
|
197 | + } |
|
198 | + } |
|
199 | + } |
|
200 | + } |
|
201 | + return $files; |
|
202 | + } |
|
203 | 203 | |
204 | - /** |
|
205 | - * Get the temporary base directory configured on the server |
|
206 | - * |
|
207 | - * @return string Path to the temporary directory or null |
|
208 | - * @throws \UnexpectedValueException |
|
209 | - */ |
|
210 | - public function getTempBaseDir() { |
|
211 | - if ($this->tmpBaseDir) { |
|
212 | - return $this->tmpBaseDir; |
|
213 | - } |
|
204 | + /** |
|
205 | + * Get the temporary base directory configured on the server |
|
206 | + * |
|
207 | + * @return string Path to the temporary directory or null |
|
208 | + * @throws \UnexpectedValueException |
|
209 | + */ |
|
210 | + public function getTempBaseDir() { |
|
211 | + if ($this->tmpBaseDir) { |
|
212 | + return $this->tmpBaseDir; |
|
213 | + } |
|
214 | 214 | |
215 | - $directories = []; |
|
216 | - if ($temp = $this->config->getSystemValue('tempdirectory', null)) { |
|
217 | - $directories[] = $temp; |
|
218 | - } |
|
219 | - if ($temp = \OC::$server->getIniWrapper()->get('upload_tmp_dir')) { |
|
220 | - $directories[] = $temp; |
|
221 | - } |
|
222 | - if ($temp = getenv('TMP')) { |
|
223 | - $directories[] = $temp; |
|
224 | - } |
|
225 | - if ($temp = getenv('TEMP')) { |
|
226 | - $directories[] = $temp; |
|
227 | - } |
|
228 | - if ($temp = getenv('TMPDIR')) { |
|
229 | - $directories[] = $temp; |
|
230 | - } |
|
231 | - if ($temp = sys_get_temp_dir()) { |
|
232 | - $directories[] = $temp; |
|
233 | - } |
|
215 | + $directories = []; |
|
216 | + if ($temp = $this->config->getSystemValue('tempdirectory', null)) { |
|
217 | + $directories[] = $temp; |
|
218 | + } |
|
219 | + if ($temp = \OC::$server->getIniWrapper()->get('upload_tmp_dir')) { |
|
220 | + $directories[] = $temp; |
|
221 | + } |
|
222 | + if ($temp = getenv('TMP')) { |
|
223 | + $directories[] = $temp; |
|
224 | + } |
|
225 | + if ($temp = getenv('TEMP')) { |
|
226 | + $directories[] = $temp; |
|
227 | + } |
|
228 | + if ($temp = getenv('TMPDIR')) { |
|
229 | + $directories[] = $temp; |
|
230 | + } |
|
231 | + if ($temp = sys_get_temp_dir()) { |
|
232 | + $directories[] = $temp; |
|
233 | + } |
|
234 | 234 | |
235 | - foreach ($directories as $dir) { |
|
236 | - if ($this->checkTemporaryDirectory($dir)) { |
|
237 | - return $dir; |
|
238 | - } |
|
239 | - } |
|
235 | + foreach ($directories as $dir) { |
|
236 | + if ($this->checkTemporaryDirectory($dir)) { |
|
237 | + return $dir; |
|
238 | + } |
|
239 | + } |
|
240 | 240 | |
241 | - $temp = tempnam(dirname(__FILE__), ''); |
|
242 | - if (file_exists($temp)) { |
|
243 | - unlink($temp); |
|
244 | - return dirname($temp); |
|
245 | - } |
|
246 | - throw new \UnexpectedValueException('Unable to detect system temporary directory'); |
|
247 | - } |
|
241 | + $temp = tempnam(dirname(__FILE__), ''); |
|
242 | + if (file_exists($temp)) { |
|
243 | + unlink($temp); |
|
244 | + return dirname($temp); |
|
245 | + } |
|
246 | + throw new \UnexpectedValueException('Unable to detect system temporary directory'); |
|
247 | + } |
|
248 | 248 | |
249 | - /** |
|
250 | - * Check if a temporary directory is ready for use |
|
251 | - * |
|
252 | - * @param mixed $directory |
|
253 | - * @return bool |
|
254 | - */ |
|
255 | - private function checkTemporaryDirectory($directory) { |
|
256 | - // suppress any possible errors caused by is_writable |
|
257 | - // checks missing or invalid path or characters, wrong permissions etc |
|
258 | - try { |
|
259 | - if (is_writable($directory)) { |
|
260 | - return true; |
|
261 | - } |
|
262 | - } catch (\Exception $e) { |
|
263 | - } |
|
264 | - $this->log->warning('Temporary directory {dir} is not present or writable', |
|
265 | - ['dir' => $directory] |
|
266 | - ); |
|
267 | - return false; |
|
268 | - } |
|
249 | + /** |
|
250 | + * Check if a temporary directory is ready for use |
|
251 | + * |
|
252 | + * @param mixed $directory |
|
253 | + * @return bool |
|
254 | + */ |
|
255 | + private function checkTemporaryDirectory($directory) { |
|
256 | + // suppress any possible errors caused by is_writable |
|
257 | + // checks missing or invalid path or characters, wrong permissions etc |
|
258 | + try { |
|
259 | + if (is_writable($directory)) { |
|
260 | + return true; |
|
261 | + } |
|
262 | + } catch (\Exception $e) { |
|
263 | + } |
|
264 | + $this->log->warning('Temporary directory {dir} is not present or writable', |
|
265 | + ['dir' => $directory] |
|
266 | + ); |
|
267 | + return false; |
|
268 | + } |
|
269 | 269 | |
270 | - /** |
|
271 | - * Override the temporary base directory |
|
272 | - * |
|
273 | - * @param string $directory |
|
274 | - */ |
|
275 | - public function overrideTempBaseDir($directory) { |
|
276 | - $this->tmpBaseDir = $directory; |
|
277 | - } |
|
270 | + /** |
|
271 | + * Override the temporary base directory |
|
272 | + * |
|
273 | + * @param string $directory |
|
274 | + */ |
|
275 | + public function overrideTempBaseDir($directory) { |
|
276 | + $this->tmpBaseDir = $directory; |
|
277 | + } |
|
278 | 278 | |
279 | 279 | } |
@@ -54,8 +54,7 @@ |
||
54 | 54 | */ |
55 | 55 | public function getBody() { |
56 | 56 | return $this->stream ? |
57 | - $this->response->getBody()->detach(): |
|
58 | - $this->response->getBody()->getContents(); |
|
57 | + $this->response->getBody()->detach() : $this->response->getBody()->getContents(); |
|
59 | 58 | } |
60 | 59 | |
61 | 60 | /** |
@@ -33,57 +33,57 @@ |
||
33 | 33 | * @package OC\Http |
34 | 34 | */ |
35 | 35 | class Response implements IResponse { |
36 | - /** @var ResponseInterface */ |
|
37 | - private $response; |
|
36 | + /** @var ResponseInterface */ |
|
37 | + private $response; |
|
38 | 38 | |
39 | - /** |
|
40 | - * @var bool |
|
41 | - */ |
|
42 | - private $stream; |
|
39 | + /** |
|
40 | + * @var bool |
|
41 | + */ |
|
42 | + private $stream; |
|
43 | 43 | |
44 | - /** |
|
45 | - * @param ResponseInterface $response |
|
46 | - * @param bool $stream |
|
47 | - */ |
|
48 | - public function __construct(ResponseInterface $response, $stream = false) { |
|
49 | - $this->response = $response; |
|
50 | - $this->stream = $stream; |
|
51 | - } |
|
44 | + /** |
|
45 | + * @param ResponseInterface $response |
|
46 | + * @param bool $stream |
|
47 | + */ |
|
48 | + public function __construct(ResponseInterface $response, $stream = false) { |
|
49 | + $this->response = $response; |
|
50 | + $this->stream = $stream; |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * @return string|resource |
|
55 | - */ |
|
56 | - public function getBody() { |
|
57 | - return $this->stream ? |
|
58 | - $this->response->getBody()->detach(): |
|
59 | - $this->response->getBody()->getContents(); |
|
60 | - } |
|
53 | + /** |
|
54 | + * @return string|resource |
|
55 | + */ |
|
56 | + public function getBody() { |
|
57 | + return $this->stream ? |
|
58 | + $this->response->getBody()->detach(): |
|
59 | + $this->response->getBody()->getContents(); |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * @return int |
|
64 | - */ |
|
65 | - public function getStatusCode(): int { |
|
66 | - return $this->response->getStatusCode(); |
|
67 | - } |
|
62 | + /** |
|
63 | + * @return int |
|
64 | + */ |
|
65 | + public function getStatusCode(): int { |
|
66 | + return $this->response->getStatusCode(); |
|
67 | + } |
|
68 | 68 | |
69 | - /** |
|
70 | - * @param string $key |
|
71 | - * @return string |
|
72 | - */ |
|
73 | - public function getHeader(string $key): string { |
|
74 | - $headers = $this->response->getHeader($key); |
|
69 | + /** |
|
70 | + * @param string $key |
|
71 | + * @return string |
|
72 | + */ |
|
73 | + public function getHeader(string $key): string { |
|
74 | + $headers = $this->response->getHeader($key); |
|
75 | 75 | |
76 | - if (count($headers) === 0) { |
|
77 | - return ''; |
|
78 | - } |
|
76 | + if (count($headers) === 0) { |
|
77 | + return ''; |
|
78 | + } |
|
79 | 79 | |
80 | - return $headers[0]; |
|
81 | - } |
|
80 | + return $headers[0]; |
|
81 | + } |
|
82 | 82 | |
83 | - /** |
|
84 | - * @return array |
|
85 | - */ |
|
86 | - public function getHeaders(): array { |
|
87 | - return $this->response->getHeaders(); |
|
88 | - } |
|
83 | + /** |
|
84 | + * @return array |
|
85 | + */ |
|
86 | + public function getHeaders(): array { |
|
87 | + return $this->response->getHeaders(); |
|
88 | + } |
|
89 | 89 | } |
@@ -30,25 +30,25 @@ |
||
30 | 30 | parent::__construct($iterator); |
31 | 31 | |
32 | 32 | $appFolders = \OC::$APPSROOTS; |
33 | - foreach($appFolders as $key => $appFolder) { |
|
33 | + foreach ($appFolders as $key => $appFolder) { |
|
34 | 34 | $appFolders[$key] = rtrim($appFolder['path'], '/'); |
35 | 35 | } |
36 | 36 | |
37 | 37 | $excludedFolders = [ |
38 | - rtrim($root . '/data', '/'), |
|
39 | - rtrim($root . '/themes', '/'), |
|
40 | - rtrim($root . '/config', '/'), |
|
41 | - rtrim($root . '/apps', '/'), |
|
42 | - rtrim($root . '/assets', '/'), |
|
43 | - rtrim($root . '/lost+found', '/'), |
|
38 | + rtrim($root.'/data', '/'), |
|
39 | + rtrim($root.'/themes', '/'), |
|
40 | + rtrim($root.'/config', '/'), |
|
41 | + rtrim($root.'/apps', '/'), |
|
42 | + rtrim($root.'/assets', '/'), |
|
43 | + rtrim($root.'/lost+found', '/'), |
|
44 | 44 | // Ignore folders generated by updater since the updater is replaced |
45 | 45 | // after the integrity check is run. |
46 | 46 | // See https://github.com/owncloud/updater/issues/318#issuecomment-212497846 |
47 | - rtrim($root . '/updater', '/'), |
|
48 | - rtrim($root . '/_oc_upgrade', '/'), |
|
47 | + rtrim($root.'/updater', '/'), |
|
48 | + rtrim($root.'/_oc_upgrade', '/'), |
|
49 | 49 | ]; |
50 | 50 | $customDataDir = \OC::$server->getConfig()->getSystemValue('datadirectory', ''); |
51 | - if($customDataDir !== '') { |
|
51 | + if ($customDataDir !== '') { |
|
52 | 52 | $excludedFolders[] = rtrim($customDataDir, '/'); |
53 | 53 | } |
54 | 54 |
@@ -25,45 +25,45 @@ |
||
25 | 25 | namespace OC\IntegrityCheck\Iterator; |
26 | 26 | |
27 | 27 | class ExcludeFoldersByPathFilterIterator extends \RecursiveFilterIterator { |
28 | - private $excludedFolders; |
|
28 | + private $excludedFolders; |
|
29 | 29 | |
30 | - public function __construct(\RecursiveIterator $iterator, $root = '') { |
|
31 | - parent::__construct($iterator); |
|
30 | + public function __construct(\RecursiveIterator $iterator, $root = '') { |
|
31 | + parent::__construct($iterator); |
|
32 | 32 | |
33 | - $appFolders = \OC::$APPSROOTS; |
|
34 | - foreach($appFolders as $key => $appFolder) { |
|
35 | - $appFolders[$key] = rtrim($appFolder['path'], '/'); |
|
36 | - } |
|
33 | + $appFolders = \OC::$APPSROOTS; |
|
34 | + foreach($appFolders as $key => $appFolder) { |
|
35 | + $appFolders[$key] = rtrim($appFolder['path'], '/'); |
|
36 | + } |
|
37 | 37 | |
38 | - $excludedFolders = [ |
|
39 | - rtrim($root . '/data', '/'), |
|
40 | - rtrim($root . '/themes', '/'), |
|
41 | - rtrim($root . '/config', '/'), |
|
42 | - rtrim($root . '/apps', '/'), |
|
43 | - rtrim($root . '/assets', '/'), |
|
44 | - rtrim($root . '/lost+found', '/'), |
|
45 | - // Ignore folders generated by updater since the updater is replaced |
|
46 | - // after the integrity check is run. |
|
47 | - // See https://github.com/owncloud/updater/issues/318#issuecomment-212497846 |
|
48 | - rtrim($root . '/updater', '/'), |
|
49 | - rtrim($root . '/_oc_upgrade', '/'), |
|
50 | - ]; |
|
51 | - $customDataDir = \OC::$server->getConfig()->getSystemValue('datadirectory', ''); |
|
52 | - if($customDataDir !== '') { |
|
53 | - $excludedFolders[] = rtrim($customDataDir, '/'); |
|
54 | - } |
|
38 | + $excludedFolders = [ |
|
39 | + rtrim($root . '/data', '/'), |
|
40 | + rtrim($root . '/themes', '/'), |
|
41 | + rtrim($root . '/config', '/'), |
|
42 | + rtrim($root . '/apps', '/'), |
|
43 | + rtrim($root . '/assets', '/'), |
|
44 | + rtrim($root . '/lost+found', '/'), |
|
45 | + // Ignore folders generated by updater since the updater is replaced |
|
46 | + // after the integrity check is run. |
|
47 | + // See https://github.com/owncloud/updater/issues/318#issuecomment-212497846 |
|
48 | + rtrim($root . '/updater', '/'), |
|
49 | + rtrim($root . '/_oc_upgrade', '/'), |
|
50 | + ]; |
|
51 | + $customDataDir = \OC::$server->getConfig()->getSystemValue('datadirectory', ''); |
|
52 | + if($customDataDir !== '') { |
|
53 | + $excludedFolders[] = rtrim($customDataDir, '/'); |
|
54 | + } |
|
55 | 55 | |
56 | - $this->excludedFolders = array_merge($excludedFolders, $appFolders); |
|
57 | - } |
|
56 | + $this->excludedFolders = array_merge($excludedFolders, $appFolders); |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * @return bool |
|
61 | - */ |
|
62 | - public function accept() { |
|
63 | - return !\in_array( |
|
64 | - $this->current()->getPathName(), |
|
65 | - $this->excludedFolders, |
|
66 | - true |
|
67 | - ); |
|
68 | - } |
|
59 | + /** |
|
60 | + * @return bool |
|
61 | + */ |
|
62 | + public function accept() { |
|
63 | + return !\in_array( |
|
64 | + $this->current()->getPathName(), |
|
65 | + $this->excludedFolders, |
|
66 | + true |
|
67 | + ); |
|
68 | + } |
|
69 | 69 | } |
@@ -35,46 +35,46 @@ |
||
35 | 35 | */ |
36 | 36 | class HintException extends \Exception { |
37 | 37 | |
38 | - private $hint; |
|
38 | + private $hint; |
|
39 | 39 | |
40 | - /** |
|
41 | - * HintException constructor. |
|
42 | - * |
|
43 | - * @param string $message The error message. It will be not revealed to the |
|
44 | - * the user (unless the hint is empty) and thus |
|
45 | - * should be not translated. |
|
46 | - * @param string $hint A useful message that is presented to the end |
|
47 | - * user. It should be translated, but must not |
|
48 | - * contain sensitive data. |
|
49 | - * @param int $code |
|
50 | - * @param \Exception|null $previous |
|
51 | - */ |
|
52 | - public function __construct($message, $hint = '', $code = 0, \Exception $previous = null) { |
|
53 | - $this->hint = $hint; |
|
54 | - parent::__construct($message, $code, $previous); |
|
55 | - } |
|
40 | + /** |
|
41 | + * HintException constructor. |
|
42 | + * |
|
43 | + * @param string $message The error message. It will be not revealed to the |
|
44 | + * the user (unless the hint is empty) and thus |
|
45 | + * should be not translated. |
|
46 | + * @param string $hint A useful message that is presented to the end |
|
47 | + * user. It should be translated, but must not |
|
48 | + * contain sensitive data. |
|
49 | + * @param int $code |
|
50 | + * @param \Exception|null $previous |
|
51 | + */ |
|
52 | + public function __construct($message, $hint = '', $code = 0, \Exception $previous = null) { |
|
53 | + $this->hint = $hint; |
|
54 | + parent::__construct($message, $code, $previous); |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * Returns a string representation of this Exception that includes the error |
|
59 | - * code, the message and the hint. |
|
60 | - * |
|
61 | - * @return string |
|
62 | - */ |
|
63 | - public function __toString() { |
|
64 | - return __CLASS__ . ": [{$this->code}]: {$this->message} ({$this->hint})\n"; |
|
65 | - } |
|
57 | + /** |
|
58 | + * Returns a string representation of this Exception that includes the error |
|
59 | + * code, the message and the hint. |
|
60 | + * |
|
61 | + * @return string |
|
62 | + */ |
|
63 | + public function __toString() { |
|
64 | + return __CLASS__ . ": [{$this->code}]: {$this->message} ({$this->hint})\n"; |
|
65 | + } |
|
66 | 66 | |
67 | - /** |
|
68 | - * Returns the hint with the intention to be presented to the end user. If |
|
69 | - * an empty hint was specified upon instatiation, the message is returned |
|
70 | - * instead. |
|
71 | - * |
|
72 | - * @return string |
|
73 | - */ |
|
74 | - public function getHint() { |
|
75 | - if (empty($this->hint)) { |
|
76 | - return $this->message; |
|
77 | - } |
|
78 | - return $this->hint; |
|
79 | - } |
|
67 | + /** |
|
68 | + * Returns the hint with the intention to be presented to the end user. If |
|
69 | + * an empty hint was specified upon instatiation, the message is returned |
|
70 | + * instead. |
|
71 | + * |
|
72 | + * @return string |
|
73 | + */ |
|
74 | + public function getHint() { |
|
75 | + if (empty($this->hint)) { |
|
76 | + return $this->message; |
|
77 | + } |
|
78 | + return $this->hint; |
|
79 | + } |
|
80 | 80 | } |
@@ -61,7 +61,7 @@ |
||
61 | 61 | * @return string |
62 | 62 | */ |
63 | 63 | public function __toString() { |
64 | - return __CLASS__ . ": [{$this->code}]: {$this->message} ({$this->hint})\n"; |
|
64 | + return __CLASS__.": [{$this->code}]: {$this->message} ({$this->hint})\n"; |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | /** |
@@ -26,79 +26,79 @@ |
||
26 | 26 | use OCP\Diagnostics\IEvent; |
27 | 27 | |
28 | 28 | class Event implements IEvent { |
29 | - /** |
|
30 | - * @var string |
|
31 | - */ |
|
32 | - protected $id; |
|
29 | + /** |
|
30 | + * @var string |
|
31 | + */ |
|
32 | + protected $id; |
|
33 | 33 | |
34 | - /** |
|
35 | - * @var float |
|
36 | - */ |
|
37 | - protected $start; |
|
34 | + /** |
|
35 | + * @var float |
|
36 | + */ |
|
37 | + protected $start; |
|
38 | 38 | |
39 | - /** |
|
40 | - * @var float |
|
41 | - */ |
|
42 | - protected $end; |
|
39 | + /** |
|
40 | + * @var float |
|
41 | + */ |
|
42 | + protected $end; |
|
43 | 43 | |
44 | - /** |
|
45 | - * @var string |
|
46 | - */ |
|
47 | - protected $description; |
|
44 | + /** |
|
45 | + * @var string |
|
46 | + */ |
|
47 | + protected $description; |
|
48 | 48 | |
49 | - /** |
|
50 | - * @param string $id |
|
51 | - * @param string $description |
|
52 | - * @param float $start |
|
53 | - */ |
|
54 | - public function __construct($id, $description, $start) { |
|
55 | - $this->id = $id; |
|
56 | - $this->description = $description; |
|
57 | - $this->start = $start; |
|
58 | - } |
|
49 | + /** |
|
50 | + * @param string $id |
|
51 | + * @param string $description |
|
52 | + * @param float $start |
|
53 | + */ |
|
54 | + public function __construct($id, $description, $start) { |
|
55 | + $this->id = $id; |
|
56 | + $this->description = $description; |
|
57 | + $this->start = $start; |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * @param float $time |
|
62 | - */ |
|
63 | - public function end($time) { |
|
64 | - $this->end = $time; |
|
65 | - } |
|
60 | + /** |
|
61 | + * @param float $time |
|
62 | + */ |
|
63 | + public function end($time) { |
|
64 | + $this->end = $time; |
|
65 | + } |
|
66 | 66 | |
67 | - /** |
|
68 | - * @return float |
|
69 | - */ |
|
70 | - public function getStart() { |
|
71 | - return $this->start; |
|
72 | - } |
|
67 | + /** |
|
68 | + * @return float |
|
69 | + */ |
|
70 | + public function getStart() { |
|
71 | + return $this->start; |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * @return string |
|
76 | - */ |
|
77 | - public function getId() { |
|
78 | - return $this->id; |
|
79 | - } |
|
74 | + /** |
|
75 | + * @return string |
|
76 | + */ |
|
77 | + public function getId() { |
|
78 | + return $this->id; |
|
79 | + } |
|
80 | 80 | |
81 | - /** |
|
82 | - * @return string |
|
83 | - */ |
|
84 | - public function getDescription() { |
|
85 | - return $this->description; |
|
86 | - } |
|
81 | + /** |
|
82 | + * @return string |
|
83 | + */ |
|
84 | + public function getDescription() { |
|
85 | + return $this->description; |
|
86 | + } |
|
87 | 87 | |
88 | - /** |
|
89 | - * @return float |
|
90 | - */ |
|
91 | - public function getEnd() { |
|
92 | - return $this->end; |
|
93 | - } |
|
88 | + /** |
|
89 | + * @return float |
|
90 | + */ |
|
91 | + public function getEnd() { |
|
92 | + return $this->end; |
|
93 | + } |
|
94 | 94 | |
95 | - /** |
|
96 | - * @return float |
|
97 | - */ |
|
98 | - public function getDuration() { |
|
99 | - if (!$this->end) { |
|
100 | - $this->end = microtime(true); |
|
101 | - } |
|
102 | - return $this->end - $this->start; |
|
103 | - } |
|
95 | + /** |
|
96 | + * @return float |
|
97 | + */ |
|
98 | + public function getDuration() { |
|
99 | + if (!$this->end) { |
|
100 | + $this->end = microtime(true); |
|
101 | + } |
|
102 | + return $this->end - $this->start; |
|
103 | + } |
|
104 | 104 | } |
@@ -37,54 +37,54 @@ |
||
37 | 37 | */ |
38 | 38 | class Tag extends Entity { |
39 | 39 | |
40 | - protected $owner; |
|
41 | - protected $type; |
|
42 | - protected $name; |
|
40 | + protected $owner; |
|
41 | + protected $type; |
|
42 | + protected $name; |
|
43 | 43 | |
44 | - /** |
|
45 | - * Constructor. |
|
46 | - * |
|
47 | - * @param string $owner The tag's owner |
|
48 | - * @param string $type The type of item this tag is used for |
|
49 | - * @param string $name The tag's name |
|
50 | - */ |
|
51 | - public function __construct($owner = null, $type = null, $name = null) { |
|
52 | - $this->setOwner($owner); |
|
53 | - $this->setType($type); |
|
54 | - $this->setName($name); |
|
55 | - } |
|
44 | + /** |
|
45 | + * Constructor. |
|
46 | + * |
|
47 | + * @param string $owner The tag's owner |
|
48 | + * @param string $type The type of item this tag is used for |
|
49 | + * @param string $name The tag's name |
|
50 | + */ |
|
51 | + public function __construct($owner = null, $type = null, $name = null) { |
|
52 | + $this->setOwner($owner); |
|
53 | + $this->setType($type); |
|
54 | + $this->setName($name); |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * Transform a database columnname to a property |
|
59 | - * |
|
60 | - * @param string $columnName the name of the column |
|
61 | - * @return string the property name |
|
62 | - * @todo migrate existing database columns to the correct names |
|
63 | - * to be able to drop this direct mapping |
|
64 | - */ |
|
65 | - public function columnToProperty($columnName){ |
|
66 | - if ($columnName === 'category') { |
|
67 | - return 'name'; |
|
68 | - } elseif ($columnName === 'uid') { |
|
69 | - return 'owner'; |
|
70 | - } else { |
|
71 | - return parent::columnToProperty($columnName); |
|
72 | - } |
|
73 | - } |
|
57 | + /** |
|
58 | + * Transform a database columnname to a property |
|
59 | + * |
|
60 | + * @param string $columnName the name of the column |
|
61 | + * @return string the property name |
|
62 | + * @todo migrate existing database columns to the correct names |
|
63 | + * to be able to drop this direct mapping |
|
64 | + */ |
|
65 | + public function columnToProperty($columnName){ |
|
66 | + if ($columnName === 'category') { |
|
67 | + return 'name'; |
|
68 | + } elseif ($columnName === 'uid') { |
|
69 | + return 'owner'; |
|
70 | + } else { |
|
71 | + return parent::columnToProperty($columnName); |
|
72 | + } |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * Transform a property to a database column name |
|
77 | - * |
|
78 | - * @param string $property the name of the property |
|
79 | - * @return string the column name |
|
80 | - */ |
|
81 | - public function propertyToColumn($property){ |
|
82 | - if ($property === 'name') { |
|
83 | - return 'category'; |
|
84 | - } elseif ($property === 'owner') { |
|
85 | - return 'uid'; |
|
86 | - } else { |
|
87 | - return parent::propertyToColumn($property); |
|
88 | - } |
|
89 | - } |
|
75 | + /** |
|
76 | + * Transform a property to a database column name |
|
77 | + * |
|
78 | + * @param string $property the name of the property |
|
79 | + * @return string the column name |
|
80 | + */ |
|
81 | + public function propertyToColumn($property){ |
|
82 | + if ($property === 'name') { |
|
83 | + return 'category'; |
|
84 | + } elseif ($property === 'owner') { |
|
85 | + return 'uid'; |
|
86 | + } else { |
|
87 | + return parent::propertyToColumn($property); |
|
88 | + } |
|
89 | + } |
|
90 | 90 | } |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | * @todo migrate existing database columns to the correct names |
63 | 63 | * to be able to drop this direct mapping |
64 | 64 | */ |
65 | - public function columnToProperty($columnName){ |
|
65 | + public function columnToProperty($columnName) { |
|
66 | 66 | if ($columnName === 'category') { |
67 | 67 | return 'name'; |
68 | 68 | } elseif ($columnName === 'uid') { |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | * @param string $property the name of the property |
79 | 79 | * @return string the column name |
80 | 80 | */ |
81 | - public function propertyToColumn($property){ |
|
81 | + public function propertyToColumn($property) { |
|
82 | 82 | if ($property === 'name') { |
83 | 83 | return 'category'; |
84 | 84 | } elseif ($property === 'owner') { |
@@ -134,7 +134,7 @@ |
||
134 | 134 | } |
135 | 135 | if(is_dir($source.'/'.$file)) { |
136 | 136 | $this->addRecursive($path.'/'.$file, $source.'/'.$file); |
137 | - }else{ |
|
137 | + } else{ |
|
138 | 138 | $this->addFile($path.'/'.$file, $source.'/'.$file); |
139 | 139 | } |
140 | 140 | } |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | * @param string $source either a local file or string data |
50 | 50 | * @return bool |
51 | 51 | */ |
52 | - public abstract function addFile($path, $source=''); |
|
52 | + public abstract function addFile($path, $source = ''); |
|
53 | 53 | /** |
54 | 54 | * rename a file or folder in the archive |
55 | 55 | * @param string $source |
@@ -126,15 +126,15 @@ discard block |
||
126 | 126 | */ |
127 | 127 | public function addRecursive($path, $source) { |
128 | 128 | $dh = opendir($source); |
129 | - if(is_resource($dh)) { |
|
129 | + if (is_resource($dh)) { |
|
130 | 130 | $this->addFolder($path); |
131 | 131 | while (($file = readdir($dh)) !== false) { |
132 | - if($file === '.' || $file === '..') { |
|
132 | + if ($file === '.' || $file === '..') { |
|
133 | 133 | continue; |
134 | 134 | } |
135 | - if(is_dir($source.'/'.$file)) { |
|
135 | + if (is_dir($source.'/'.$file)) { |
|
136 | 136 | $this->addRecursive($path.'/'.$file, $source.'/'.$file); |
137 | - }else{ |
|
137 | + } else { |
|
138 | 138 | $this->addFile($path.'/'.$file, $source.'/'.$file); |
139 | 139 | } |
140 | 140 | } |
@@ -31,110 +31,110 @@ |
||
31 | 31 | namespace OC\Archive; |
32 | 32 | |
33 | 33 | abstract class Archive { |
34 | - /** |
|
35 | - * @param $source |
|
36 | - */ |
|
37 | - public abstract function __construct($source); |
|
38 | - /** |
|
39 | - * add an empty folder to the archive |
|
40 | - * @param string $path |
|
41 | - * @return bool |
|
42 | - */ |
|
43 | - public abstract function addFolder($path); |
|
44 | - /** |
|
45 | - * add a file to the archive |
|
46 | - * @param string $path |
|
47 | - * @param string $source either a local file or string data |
|
48 | - * @return bool |
|
49 | - */ |
|
50 | - public abstract function addFile($path, $source=''); |
|
51 | - /** |
|
52 | - * rename a file or folder in the archive |
|
53 | - * @param string $source |
|
54 | - * @param string $dest |
|
55 | - * @return bool |
|
56 | - */ |
|
57 | - public abstract function rename($source, $dest); |
|
58 | - /** |
|
59 | - * get the uncompressed size of a file in the archive |
|
60 | - * @param string $path |
|
61 | - * @return int |
|
62 | - */ |
|
63 | - public abstract function filesize($path); |
|
64 | - /** |
|
65 | - * get the last modified time of a file in the archive |
|
66 | - * @param string $path |
|
67 | - * @return int |
|
68 | - */ |
|
69 | - public abstract function mtime($path); |
|
70 | - /** |
|
71 | - * get the files in a folder |
|
72 | - * @param string $path |
|
73 | - * @return array |
|
74 | - */ |
|
75 | - public abstract function getFolder($path); |
|
76 | - /** |
|
77 | - * get all files in the archive |
|
78 | - * @return array |
|
79 | - */ |
|
80 | - public abstract function getFiles(); |
|
81 | - /** |
|
82 | - * get the content of a file |
|
83 | - * @param string $path |
|
84 | - * @return string |
|
85 | - */ |
|
86 | - public abstract function getFile($path); |
|
87 | - /** |
|
88 | - * extract a single file from the archive |
|
89 | - * @param string $path |
|
90 | - * @param string $dest |
|
91 | - * @return bool |
|
92 | - */ |
|
93 | - public abstract function extractFile($path, $dest); |
|
94 | - /** |
|
95 | - * extract the archive |
|
96 | - * @param string $dest |
|
97 | - * @return bool |
|
98 | - */ |
|
99 | - public abstract function extract($dest); |
|
100 | - /** |
|
101 | - * check if a file or folder exists in the archive |
|
102 | - * @param string $path |
|
103 | - * @return bool |
|
104 | - */ |
|
105 | - public abstract function fileExists($path); |
|
106 | - /** |
|
107 | - * remove a file or folder from the archive |
|
108 | - * @param string $path |
|
109 | - * @return bool |
|
110 | - */ |
|
111 | - public abstract function remove($path); |
|
112 | - /** |
|
113 | - * get a file handler |
|
114 | - * @param string $path |
|
115 | - * @param string $mode |
|
116 | - * @return resource |
|
117 | - */ |
|
118 | - public abstract function getStream($path, $mode); |
|
119 | - /** |
|
120 | - * add a folder and all its content |
|
121 | - * @param string $path |
|
122 | - * @param string $source |
|
123 | - */ |
|
124 | - public function addRecursive($path, $source) { |
|
125 | - $dh = opendir($source); |
|
126 | - if(is_resource($dh)) { |
|
127 | - $this->addFolder($path); |
|
128 | - while (($file = readdir($dh)) !== false) { |
|
129 | - if($file === '.' || $file === '..') { |
|
130 | - continue; |
|
131 | - } |
|
132 | - if(is_dir($source.'/'.$file)) { |
|
133 | - $this->addRecursive($path.'/'.$file, $source.'/'.$file); |
|
134 | - }else{ |
|
135 | - $this->addFile($path.'/'.$file, $source.'/'.$file); |
|
136 | - } |
|
137 | - } |
|
138 | - } |
|
139 | - } |
|
34 | + /** |
|
35 | + * @param $source |
|
36 | + */ |
|
37 | + public abstract function __construct($source); |
|
38 | + /** |
|
39 | + * add an empty folder to the archive |
|
40 | + * @param string $path |
|
41 | + * @return bool |
|
42 | + */ |
|
43 | + public abstract function addFolder($path); |
|
44 | + /** |
|
45 | + * add a file to the archive |
|
46 | + * @param string $path |
|
47 | + * @param string $source either a local file or string data |
|
48 | + * @return bool |
|
49 | + */ |
|
50 | + public abstract function addFile($path, $source=''); |
|
51 | + /** |
|
52 | + * rename a file or folder in the archive |
|
53 | + * @param string $source |
|
54 | + * @param string $dest |
|
55 | + * @return bool |
|
56 | + */ |
|
57 | + public abstract function rename($source, $dest); |
|
58 | + /** |
|
59 | + * get the uncompressed size of a file in the archive |
|
60 | + * @param string $path |
|
61 | + * @return int |
|
62 | + */ |
|
63 | + public abstract function filesize($path); |
|
64 | + /** |
|
65 | + * get the last modified time of a file in the archive |
|
66 | + * @param string $path |
|
67 | + * @return int |
|
68 | + */ |
|
69 | + public abstract function mtime($path); |
|
70 | + /** |
|
71 | + * get the files in a folder |
|
72 | + * @param string $path |
|
73 | + * @return array |
|
74 | + */ |
|
75 | + public abstract function getFolder($path); |
|
76 | + /** |
|
77 | + * get all files in the archive |
|
78 | + * @return array |
|
79 | + */ |
|
80 | + public abstract function getFiles(); |
|
81 | + /** |
|
82 | + * get the content of a file |
|
83 | + * @param string $path |
|
84 | + * @return string |
|
85 | + */ |
|
86 | + public abstract function getFile($path); |
|
87 | + /** |
|
88 | + * extract a single file from the archive |
|
89 | + * @param string $path |
|
90 | + * @param string $dest |
|
91 | + * @return bool |
|
92 | + */ |
|
93 | + public abstract function extractFile($path, $dest); |
|
94 | + /** |
|
95 | + * extract the archive |
|
96 | + * @param string $dest |
|
97 | + * @return bool |
|
98 | + */ |
|
99 | + public abstract function extract($dest); |
|
100 | + /** |
|
101 | + * check if a file or folder exists in the archive |
|
102 | + * @param string $path |
|
103 | + * @return bool |
|
104 | + */ |
|
105 | + public abstract function fileExists($path); |
|
106 | + /** |
|
107 | + * remove a file or folder from the archive |
|
108 | + * @param string $path |
|
109 | + * @return bool |
|
110 | + */ |
|
111 | + public abstract function remove($path); |
|
112 | + /** |
|
113 | + * get a file handler |
|
114 | + * @param string $path |
|
115 | + * @param string $mode |
|
116 | + * @return resource |
|
117 | + */ |
|
118 | + public abstract function getStream($path, $mode); |
|
119 | + /** |
|
120 | + * add a folder and all its content |
|
121 | + * @param string $path |
|
122 | + * @param string $source |
|
123 | + */ |
|
124 | + public function addRecursive($path, $source) { |
|
125 | + $dh = opendir($source); |
|
126 | + if(is_resource($dh)) { |
|
127 | + $this->addFolder($path); |
|
128 | + while (($file = readdir($dh)) !== false) { |
|
129 | + if($file === '.' || $file === '..') { |
|
130 | + continue; |
|
131 | + } |
|
132 | + if(is_dir($source.'/'.$file)) { |
|
133 | + $this->addRecursive($path.'/'.$file, $source.'/'.$file); |
|
134 | + }else{ |
|
135 | + $this->addFile($path.'/'.$file, $source.'/'.$file); |
|
136 | + } |
|
137 | + } |
|
138 | + } |
|
139 | + } |
|
140 | 140 | } |