Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Nextcloud
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TeDomum
Nextcloud
Commits
2ac6f3a4
Commit
2ac6f3a4
authored
10 years ago
by
Lukas Reschke
Browse files
Options
Downloads
Patches
Plain Diff
Clean-up code and use proper exception types
parent
fccede8f
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/private/files/storage/dav.php
+48
-6
48 additions, 6 deletions
lib/private/files/storage/dav.php
with
48 additions
and
6 deletions
lib/private/files/storage/dav.php
+
48
−
6
View file @
2ac6f3a4
...
...
@@ -10,8 +10,13 @@ namespace OC\Files\Storage;
use
OCP\Files\StorageInvalidException
;
use
OCP\Files\StorageNotAvailableException
;
use
Sabre\
DAV
\ClientHttpException
;
use
Sabre\
HTTP
\ClientHttpException
;
/**
* Class DAV
*
* @package OC\Files\Storage
*/
class
DAV
extends
\OC\Files\Storage\Common
{
protected
$password
;
protected
$user
;
...
...
@@ -25,8 +30,13 @@ class DAV extends \OC\Files\Storage\Common {
*/
private
$client
;
private
static
$tempFiles
=
array
();
/** @var array */
private
static
$tempFiles
=
[];
/**
* @param array $params
* @throws \Exception
*/
public
function
__construct
(
$params
)
{
if
(
isset
(
$params
[
'host'
])
&&
isset
(
$params
[
'user'
])
&&
isset
(
$params
[
'password'
]))
{
$host
=
$params
[
'host'
];
...
...
@@ -83,10 +93,12 @@ class DAV extends \OC\Files\Storage\Common {
}
}
/** {@inheritdoc} */
public
function
getId
()
{
return
'webdav::'
.
$this
->
user
.
'@'
.
$this
->
host
.
'/'
.
$this
->
root
;
}
/** {@inheritdoc} */
public
function
createBaseUri
()
{
$baseUri
=
'http'
;
if
(
$this
->
secure
)
{
...
...
@@ -96,12 +108,14 @@ class DAV extends \OC\Files\Storage\Common {
return
$baseUri
;
}
/** {@inheritdoc} */
public
function
mkdir
(
$path
)
{
$this
->
init
();
$path
=
$this
->
cleanPath
(
$path
);
return
$this
->
simpleResponse
(
'MKCOL'
,
$path
,
null
,
201
);
}
/** {@inheritdoc} */
public
function
rmdir
(
$path
)
{
$this
->
init
();
$path
=
$this
->
cleanPath
(
$path
)
.
'/'
;
...
...
@@ -110,6 +124,7 @@ class DAV extends \OC\Files\Storage\Common {
return
$this
->
simpleResponse
(
'DELETE'
,
$path
,
null
,
204
);
}
/** {@inheritdoc} */
public
function
opendir
(
$path
)
{
$this
->
init
();
$path
=
$this
->
cleanPath
(
$path
);
...
...
@@ -138,6 +153,7 @@ class DAV extends \OC\Files\Storage\Common {
}
}
/** {@inheritdoc} */
public
function
filetype
(
$path
)
{
$this
->
init
();
$path
=
$this
->
cleanPath
(
$path
);
...
...
@@ -161,6 +177,7 @@ class DAV extends \OC\Files\Storage\Common {
}
}
/** {@inheritdoc} */
public
function
file_exists
(
$path
)
{
$this
->
init
();
$path
=
$this
->
cleanPath
(
$path
);
...
...
@@ -180,11 +197,13 @@ class DAV extends \OC\Files\Storage\Common {
}
}
/** {@inheritdoc} */
public
function
unlink
(
$path
)
{
$this
->
init
();
return
$this
->
simpleResponse
(
'DELETE'
,
$path
,
null
,
204
);
}
/** {@inheritdoc} */
public
function
fopen
(
$path
,
$mode
)
{
$this
->
init
();
$path
=
$this
->
cleanPath
(
$path
);
...
...
@@ -254,6 +273,9 @@ class DAV extends \OC\Files\Storage\Common {
}
}
/**
* @param string $tmpFile
*/
public
function
writeBack
(
$tmpFile
)
{
if
(
isset
(
self
::
$tempFiles
[
$tmpFile
]))
{
$this
->
uploadFile
(
$tmpFile
,
self
::
$tempFiles
[
$tmpFile
]);
...
...
@@ -261,6 +283,7 @@ class DAV extends \OC\Files\Storage\Common {
}
}
/** {@inheritdoc} */
public
function
free_space
(
$path
)
{
$this
->
init
();
$path
=
$this
->
cleanPath
(
$path
);
...
...
@@ -276,6 +299,7 @@ class DAV extends \OC\Files\Storage\Common {
}
}
/** {@inheritdoc} */
public
function
touch
(
$path
,
$mtime
=
null
)
{
$this
->
init
();
if
(
is_null
(
$mtime
))
{
...
...
@@ -304,6 +328,10 @@ class DAV extends \OC\Files\Storage\Common {
return
true
;
}
/**
* @param string $path
* @param string $target
*/
protected
function
uploadFile
(
$path
,
$target
)
{
$this
->
init
();
$source
=
fopen
(
$path
,
'r'
);
...
...
@@ -335,6 +363,7 @@ class DAV extends \OC\Files\Storage\Common {
$this
->
removeCachedFile
(
$target
);
}
/** {@inheritdoc} */
public
function
rename
(
$path1
,
$path2
)
{
$this
->
init
();
$path1
=
$this
->
encodePath
(
$this
->
cleanPath
(
$path1
));
...
...
@@ -354,6 +383,7 @@ class DAV extends \OC\Files\Storage\Common {
}
}
/** {@inheritdoc} */
public
function
copy
(
$path1
,
$path2
)
{
$this
->
init
();
$path1
=
$this
->
encodePath
(
$this
->
cleanPath
(
$path1
));
...
...
@@ -372,6 +402,7 @@ class DAV extends \OC\Files\Storage\Common {
}
}
/** {@inheritdoc} */
public
function
stat
(
$path
)
{
$this
->
init
();
$path
=
$this
->
cleanPath
(
$path
);
...
...
@@ -394,6 +425,7 @@ class DAV extends \OC\Files\Storage\Common {
}
}
/** {@inheritdoc} */
public
function
getMimeType
(
$path
)
{
$this
->
init
();
$path
=
$this
->
cleanPath
(
$path
);
...
...
@@ -426,6 +458,7 @@ class DAV extends \OC\Files\Storage\Common {
/**
* @param string $path
* @return string
*/
public
function
cleanPath
(
$path
)
{
if
(
$path
===
""
)
{
...
...
@@ -450,7 +483,11 @@ class DAV extends \OC\Files\Storage\Common {
/**
* @param string $method
* @param string $path
* @param integer $expected
* @param string|resource|null $body
* @param int $expected
* @return bool
* @throws StorageInvalidException
* @throws StorageNotAvailableException
*/
private
function
simpleResponse
(
$method
,
$path
,
$body
,
$expected
)
{
$path
=
$this
->
cleanPath
(
$path
);
...
...
@@ -482,22 +519,27 @@ class DAV extends \OC\Files\Storage\Common {
}
}
/** {@inheritdoc} */
public
function
isUpdatable
(
$path
)
{
return
(
bool
)(
$this
->
getPermissions
(
$path
)
&
\OCP\Constants
::
PERMISSION_UPDATE
);
}
/** {@inheritdoc} */
public
function
isCreatable
(
$path
)
{
return
(
bool
)(
$this
->
getPermissions
(
$path
)
&
\OCP\Constants
::
PERMISSION_CREATE
);
}
/** {@inheritdoc} */
public
function
isSharable
(
$path
)
{
return
(
bool
)(
$this
->
getPermissions
(
$path
)
&
\OCP\Constants
::
PERMISSION_SHARE
);
}
/** {@inheritdoc} */
public
function
isDeletable
(
$path
)
{
return
(
bool
)(
$this
->
getPermissions
(
$path
)
&
\OCP\Constants
::
PERMISSION_DELETE
);
}
/** {@inheritdoc} */
public
function
getPermissions
(
$path
)
{
$this
->
init
();
$path
=
$this
->
cleanPath
(
$path
);
...
...
@@ -567,7 +609,7 @@ class DAV extends \OC\Files\Storage\Common {
$remoteMtime
=
strtotime
(
$response
[
'{DAV:}getlastmodified'
]);
return
$remoteMtime
>
$time
;
}
}
catch
(
Exception
$e
)
{
}
catch
(
\
Exception
$e
)
{
if
(
$e
->
getHttpStatus
()
===
404
)
{
return
false
;
}
...
...
@@ -580,13 +622,13 @@ class DAV extends \OC\Files\Storage\Common {
* Convert sabre DAV exception to a storage exception,
* then throw it
*
* @param ClientException $e sabre exception
* @param Client
Http
Exception $e sabre exception
* @throws StorageInvalidException if the storage is invalid, for example
* when the authentication expired or is invalid
* @throws StorageNotAvailableException if the storage is not available,
* which might be temporary
*/
private
function
convertSabreException
(
ClientException
$e
)
{
private
function
convertSabreException
(
Client
Http
Exception
$e
)
{
\OCP\Util
::
writeLog
(
'files_external'
,
$e
->
getMessage
(),
\OCP\Util
::
ERROR
);
if
(
$e
->
getHttpStatus
()
===
401
)
{
// either password was changed or was invalid all along
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment