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
5fafd551
Commit
5fafd551
authored
11 years ago
by
Björn Schießle
Browse files
Options
Downloads
Patches
Plain Diff
make sure that only one process can enter the migration mode
parent
4f0f537b
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
apps/files_encryption/hooks/hooks.php
+3
-3
3 additions, 3 deletions
apps/files_encryption/hooks/hooks.php
apps/files_encryption/lib/util.php
+74
-9
74 additions, 9 deletions
apps/files_encryption/lib/util.php
with
77 additions
and
12 deletions
apps/files_encryption/hooks/hooks.php
+
3
−
3
View file @
5fafd551
...
...
@@ -67,10 +67,10 @@ class Hooks {
$session
->
setPrivateKey
(
$privateKey
,
$params
[
'uid'
]);
// Check if first-run file migration has already been performed
$
migrationCompleted
=
$util
->
get
Migration
Status
();
$
ready
=
$util
->
begin
Migration
();
// If migration not yet done
if
(
!
$migrationCompleted
)
{
if
(
$ready
)
{
$userView
=
new
\OC_FilesystemView
(
'/'
.
$params
[
'uid'
]);
...
...
@@ -102,7 +102,7 @@ class Hooks {
}
// Register successful migration in DB
$util
->
set
Migration
Status
(
1
);
$util
->
finish
Migration
(
);
}
...
...
This diff is collapsed.
Click to expand it.
apps/files_encryption/lib/util.php
+
74
−
9
View file @
5fafd551
...
...
@@ -1058,7 +1058,7 @@ class Util {
* @param $status
* @return bool
*/
p
ublic
function
setMigrationStatus
(
$status
)
{
p
rivate
function
setMigrationStatus
(
$status
)
{
$sql
=
'UPDATE `*PREFIX*encryption` SET `migration_status` = ? WHERE `uid` = ?'
;
...
...
@@ -1074,7 +1074,7 @@ class Util {
return
true
;
}
else
{
\OCP\Util
::
writeLog
(
'Encryption library'
,
"Could not set migration status for "
.
$this
->
userId
,
\OCP\Util
::
ERROR
);
return
false
;
}
...
...
@@ -1082,12 +1082,80 @@ class Util {
}
/**
* @brief Check whether pwd recovery is enabled for a given user
* @return bool 1 = yes, 0 = no, false = no record
* @brief start migration mode to initially encrypt users data
* @return boolean
*/
public
function
beginMigration
()
{
$return
=
false
;
$transaction
=
\OC_DB
::
beginTransaction
();
if
(
$transaction
===
false
)
{
\OCP\Util
::
writeLog
(
'Encryption library'
,
"Your database migration doesn't support transactions"
,
\OCP\Util
::
WARN
);
}
$migrationStatus
=
$this
->
getMigrationStatus
();
if
(
$migrationStatus
===
'0'
)
{
$return
=
$this
->
setMigrationStatus
(
-
1
);
if
(
$return
===
true
)
{
\OCP\Util
::
writeLog
(
'Encryption library'
,
"Enter migration mode for initial encryption for user "
.
$this
->
userId
,
\OCP\Util
::
INFO
);
}
else
{
\OCP\Util
::
writeLog
(
'Encryption library'
,
"Could not activate migration mode for "
.
$this
->
userId
.
", encryption aborted"
,
\OCP\Util
::
ERROR
);
}
}
else
{
\OCP\Util
::
writeLog
(
'Encryption library'
,
"Another process already performs the migration for user "
.
$this
->
userId
,
\OCP\Util
::
INFO
);
}
\OC_DB
::
commit
();
return
$return
;
}
/**
* @brief close migration mode after users data has been encrypted successfully
* @return boolean
*/
public
function
finishMigration
()
{
$return
=
false
;
$transaction
=
\OC_DB
::
beginTransaction
();
if
(
$transaction
===
false
)
{
\OCP\Util
::
writeLog
(
'Encryption library'
,
"Your database migration doesn't support transactions"
,
\OCP\Util
::
WARN
);
}
$migrationStatus
=
$this
->
getMigrationStatus
();
if
(
$migrationStatus
===
'-1'
)
{
$return
=
$this
->
setMigrationStatus
(
1
);
if
(
$return
===
true
)
{
\OCP\Util
::
writeLog
(
'Encryption library'
,
"Leave migration mode for: "
.
$this
->
userId
.
" successfully."
,
\OCP\Util
::
INFO
);
}
else
{
\OCP\Util
::
writeLog
(
'Encryption library'
,
"Could not deactivate migration mode for "
.
$this
->
userId
,
\OCP\Util
::
ERROR
);
}
}
else
{
\OCP\Util
::
writeLog
(
'Encryption library'
,
"Someone else finished the migration mode to early for user "
.
$this
->
userId
,
\OCP\Util
::
ERROR
);
}
\OC_DB
::
commit
();
return
$return
;
}
/**
* @brief check if files are already migrated to the encryption system
* @return '1' = yes, '0' = no, '-1' = migration in progress, false = no record
* @note If records are not being returned, check for a hidden space
* at the start of the uid in db
*/
p
ublic
function
getMigrationStatus
()
{
p
rivate
function
getMigrationStatus
()
{
$sql
=
'SELECT `migration_status` FROM `*PREFIX*encryption` WHERE `uid` = ?'
;
...
...
@@ -1112,14 +1180,11 @@ class Util {
// If no record is found
if
(
empty
(
$migrationStatus
))
{
\OCP\Util
::
writeLog
(
'Encryption library'
,
"Could not get migration status for "
.
$this
->
userId
.
", no record found"
,
\OCP\Util
::
ERROR
);
return
false
;
// If a record is found
}
else
{
return
$migrationStatus
[
0
];
}
}
...
...
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