Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
die_coolen_jungs
our_own_cloud_project
Commits
75c72672
Commit
75c72672
authored
Nov 11, 2016
by
Vincent Petry
Committed by
GitHub
Nov 11, 2016
Browse files
Merge pull request #26561 from owncloud/fed-allowrenamepartfile
Allow renaming part files on perm masked storage
parents
41c70842
54a87a7e
Changes
2
Hide whitespace changes
Inline
Side-by-side
lib/private/Files/Storage/Wrapper/PermissionsMask.php
View file @
75c72672
...
...
@@ -76,8 +76,13 @@ class PermissionsMask extends Wrapper {
return
$this
->
storage
->
getPermissions
(
$path
)
&
$this
->
mask
;
}
private
function
isPartFile
(
$path
)
{
return
pathinfo
(
$path
,
PATHINFO_EXTENSION
)
===
'part'
;
}
public
function
rename
(
$path1
,
$path2
)
{
return
$this
->
checkMask
(
Constants
::
PERMISSION_UPDATE
)
and
parent
::
rename
(
$path1
,
$path2
);
// allow renaming part files
return
(
$this
->
isPartFile
(
$path1
)
||
$this
->
checkMask
(
Constants
::
PERMISSION_UPDATE
))
&&
parent
::
rename
(
$path1
,
$path2
);
}
public
function
copy
(
$path1
,
$path2
)
{
...
...
@@ -86,7 +91,7 @@ class PermissionsMask extends Wrapper {
public
function
touch
(
$path
,
$mtime
=
null
)
{
$permissions
=
$this
->
file_exists
(
$path
)
?
Constants
::
PERMISSION_UPDATE
:
Constants
::
PERMISSION_CREATE
;
return
$this
->
checkMask
(
$permissions
)
and
parent
::
touch
(
$path
,
$mtime
);
return
(
$this
->
isPartFile
(
$path
)
||
$this
->
checkMask
(
$permissions
)
)
&&
parent
::
touch
(
$path
,
$mtime
);
}
public
function
mkdir
(
$path
)
{
...
...
@@ -103,7 +108,7 @@ class PermissionsMask extends Wrapper {
public
function
file_put_contents
(
$path
,
$data
)
{
$permissions
=
$this
->
file_exists
(
$path
)
?
Constants
::
PERMISSION_UPDATE
:
Constants
::
PERMISSION_CREATE
;
return
$this
->
checkMask
(
$permissions
)
and
parent
::
file_put_contents
(
$path
,
$data
);
return
(
$this
->
isPartFile
(
$path
)
||
$this
->
checkMask
(
$permissions
)
)
&&
parent
::
file_put_contents
(
$path
,
$data
);
}
public
function
fopen
(
$path
,
$mode
)
{
...
...
@@ -111,7 +116,7 @@ class PermissionsMask extends Wrapper {
return
parent
::
fopen
(
$path
,
$mode
);
}
else
{
$permissions
=
$this
->
file_exists
(
$path
)
?
Constants
::
PERMISSION_UPDATE
:
Constants
::
PERMISSION_CREATE
;
return
$this
->
checkMask
(
$permissions
)
?
parent
::
fopen
(
$path
,
$mode
)
:
false
;
return
(
$this
->
isPartFile
(
$path
)
||
$this
->
checkMask
(
$permissions
)
)
?
parent
::
fopen
(
$path
,
$mode
)
:
false
;
}
}
...
...
tests/lib/Files/Storage/Wrapper/PermissionsMaskTest.php
View file @
75c72672
...
...
@@ -102,4 +102,34 @@ class PermissionsMaskTest extends \Test\Files\Storage\Storage {
$storage
=
$this
->
getMaskedStorage
(
Constants
::
PERMISSION_ALL
-
Constants
::
PERMISSION_CREATE
);
$this
->
assertFalse
(
$storage
->
fopen
(
'foo'
,
'w'
));
}
public
function
testRenameExistingFileNoUpdate
()
{
$this
->
sourceStorage
->
touch
(
'foo'
);
$storage
=
$this
->
getMaskedStorage
(
Constants
::
PERMISSION_ALL
-
Constants
::
PERMISSION_UPDATE
);
$this
->
assertFalse
(
$storage
->
rename
(
'foo'
,
'bar'
));
$this
->
assertTrue
(
$storage
->
file_exists
(
'foo'
));
$this
->
assertFalse
(
$storage
->
file_exists
(
'bar'
));
}
public
function
testRenamePartFileNoPerms
()
{
$this
->
sourceStorage
->
touch
(
'foo.part'
);
$storage
=
$this
->
getMaskedStorage
(
Constants
::
PERMISSION_ALL
-
Constants
::
PERMISSION_UPDATE
-
Constants
::
PERMISSION_CREATE
);
$this
->
assertTrue
(
$storage
->
rename
(
'foo.part'
,
'bar'
));
$this
->
assertFalse
(
$storage
->
file_exists
(
'foo.part'
));
$this
->
assertTrue
(
$storage
->
file_exists
(
'bar'
));
}
public
function
testFopenPartFileNoPerms
()
{
$storage
=
$this
->
getMaskedStorage
(
Constants
::
PERMISSION_ALL
-
Constants
::
PERMISSION_UPDATE
-
Constants
::
PERMISSION_CREATE
);
$res
=
$storage
->
fopen
(
'foo.part'
,
'w'
);
fwrite
(
$res
,
'foo'
);
fclose
(
$res
);
$this
->
assertTrue
(
$storage
->
file_exists
(
'foo.part'
));
}
public
function
testFilePutContentsPartFileNoPerms
()
{
$storage
=
$this
->
getMaskedStorage
(
Constants
::
PERMISSION_ALL
-
Constants
::
PERMISSION_UPDATE
-
Constants
::
PERMISSION_CREATE
);
$this
->
assertEquals
(
3
,
$storage
->
file_put_contents
(
'foo.part'
,
'bar'
));
$this
->
assertTrue
(
$storage
->
file_exists
(
'foo.part'
));
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment