Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
our_own_cloud_project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
die_coolen_jungs
our_own_cloud_project
Commits
167f57c1
Commit
167f57c1
authored
9 years ago
by
Vincent Petry
Browse files
Options
Downloads
Patches
Plain Diff
Unlock first path on rename if second path is locked
parent
3217d4da
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/private/files/view.php
+6
-1
6 additions, 1 deletion
lib/private/files/view.php
tests/lib/files/view.php
+33
-0
33 additions, 0 deletions
tests/lib/files/view.php
with
39 additions
and
1 deletion
lib/private/files/view.php
+
6
−
1
View file @
167f57c1
...
...
@@ -631,7 +631,12 @@ class View {
}
$this
->
lockFile
(
$path1
,
ILockingProvider
::
LOCK_SHARED
,
true
);
$this
->
lockFile
(
$path2
,
ILockingProvider
::
LOCK_SHARED
,
true
);
try
{
$this
->
lockFile
(
$path2
,
ILockingProvider
::
LOCK_SHARED
,
true
);
}
catch
(
LockedException
$e
)
{
$this
->
unlockFile
(
$path1
,
ILockingProvider
::
LOCK_SHARED
);
throw
$e
;
}
$run
=
true
;
if
(
$this
->
shouldEmitHooks
()
&&
(
Cache\Scanner
::
isPartialFile
(
$path1
)
&&
!
Cache\Scanner
::
isPartialFile
(
$path2
)))
{
...
...
This diff is collapsed.
Click to expand it.
tests/lib/files/view.php
+
33
−
0
View file @
167f57c1
...
...
@@ -1758,6 +1758,39 @@ class View extends \Test\TestCase {
$this
->
assertNull
(
$this
->
getFileLockType
(
$view
,
$targetPath
),
'Target file not locked after operation'
);
}
/**
* Test rename operation: unlock first path when second path was locked
*/
public
function
testLockFileRenameUnlockOnException
()
{
$this
->
loginAsUser
(
'test'
);
$view
=
new
\OC\Files\View
(
'/'
.
$this
->
user
.
'/files/'
);
$sourcePath
=
'original.txt'
;
$targetPath
=
'target.txt'
;
$view
->
file_put_contents
(
$sourcePath
,
'meh'
);
// simulate that the target path is already locked
$view
->
lockFile
(
$targetPath
,
ILockingProvider
::
LOCK_EXCLUSIVE
);
$this
->
assertNull
(
$this
->
getFileLockType
(
$view
,
$sourcePath
),
'Source file not locked before operation'
);
$this
->
assertEquals
(
ILockingProvider
::
LOCK_EXCLUSIVE
,
$this
->
getFileLockType
(
$view
,
$targetPath
),
'Target file is locked before operation'
);
$thrown
=
false
;
try
{
$view
->
rename
(
$sourcePath
,
$targetPath
);
}
catch
(
\OCP\Lock\LockedException
$e
)
{
$thrown
=
true
;
}
$this
->
assertTrue
(
$thrown
,
'LockedException thrown'
);
$this
->
assertNull
(
$this
->
getFileLockType
(
$view
,
$sourcePath
),
'Source file not locked after operation'
);
$this
->
assertEquals
(
ILockingProvider
::
LOCK_EXCLUSIVE
,
$this
->
getFileLockType
(
$view
,
$targetPath
),
'Target file still locked after operation'
);
$view
->
unlockFile
(
$targetPath
,
ILockingProvider
::
LOCK_EXCLUSIVE
);
}
public
function
lockFileRenameOrCopyCrossStorageDataProvider
()
{
return
[
[
'rename'
,
'moveFromStorage'
,
ILockingProvider
::
LOCK_EXCLUSIVE
],
...
...
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