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
efa024cc
Commit
efa024cc
authored
12 years ago
by
Björn Schießle
Browse files
Options
Downloads
Patches
Plain Diff
fix getUidAndFilename() function
parent
b05f05ec
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
apps/files_versions/appinfo/app.php
+1
-1
1 addition, 1 deletion
apps/files_versions/appinfo/app.php
apps/files_versions/lib/versions.php
+22
-45
22 additions, 45 deletions
apps/files_versions/lib/versions.php
with
23 additions
and
46 deletions
apps/files_versions/appinfo/app.php
+
1
−
1
View file @
efa024cc
...
...
@@ -12,5 +12,5 @@ OCP\Util::addscript('files_versions', 'versions');
// Listen to write signals
OCP\Util
::
connectHook
(
'OC_Filesystem'
,
'write'
,
"OCA\Files_Versions\Hooks"
,
"write_hook"
);
// Listen to delete and rename signals
OCP\Util
::
connectHook
(
'OC_Filesystem'
,
'post
-
delete'
,
"OCA\Files_Versions\Hooks"
,
"remove_hook"
);
OCP\Util
::
connectHook
(
'OC_Filesystem'
,
'post
_
delete'
,
"OCA\Files_Versions\Hooks"
,
"remove_hook"
);
OCP\Util
::
connectHook
(
'OC_Filesystem'
,
'rename'
,
"OCA\Files_Versions\Hooks"
,
"rename_hook"
);
This diff is collapsed.
Click to expand it.
apps/files_versions/lib/versions.php
+
22
−
45
View file @
efa024cc
...
...
@@ -35,48 +35,26 @@ class Storage {
'step'
=>
604800
),
);
private
static
function
getUidAndFilename
(
$filename
)
{
if
(
\OCP\App
::
isEnabled
(
'files_sharing'
)
&&
substr
(
$filename
,
0
,
7
)
==
'/Shared'
&&
$source
=
\OCP\Share
::
getItemSharedWith
(
'file'
,
substr
(
$filename
,
7
),
\OC_Share_Backend_File
::
FORMAT_SHARED_STORAGE
))
{
$filename
=
$source
[
'path'
];
$pos
=
strpos
(
$filename
,
'/files'
,
1
);
$uid
=
substr
(
$filename
,
1
,
$pos
-
1
);
$filename
=
substr
(
$filename
,
$pos
+
6
);
}
else
{
$uid
=
\OCP\User
::
getUser
();
private
static
function
getUidAndFilename
(
$filename
)
{
$uid
=
\OC\Files\Filesystem
::
getOwner
(
$filename
);
if
(
$uid
!=
\OCP\User
::
getUser
()
)
{
$info
=
\OC\Files\Filesystem
::
getFileInfo
(
$filename
);
$ownerView
=
new
\OC\Files\View
(
'/'
.
$uid
.
'/files'
);
$filename
=
$ownerView
->
getPath
(
$info
[
'fileid'
]);
}
return
array
(
$uid
,
$filename
);
}
/**
* store a new version of a file.
*/
public
static
function
store
(
$filename
)
{
if
(
\OCP\Config
::
getSystemValue
(
'files_versions'
,
Storage
::
DEFAULTENABLED
)
==
'true'
)
{
$owner
=
\OC\Files\Filesystem
::
getOwner
(
$filename
);
if
(
$owner
!=
\OCP\User
::
getUser
()
)
{
$datadir
=
\OC_Config
::
getValue
(
"datadirectory"
,
\OC
::
$SERVERROOT
.
"/data"
);
\OC\Files\Filesystem
::
mount
(
'\OC\Files\Storage\Local'
,
array
(
'datadir'
=>
$datadir
),
'/'
.
$owner
);
$info
=
\OC\Files\Filesystem
::
getFileInfo
(
$filename
);
$id
=
$info
[
'fileid'
];
error_log
(
"id:
$id
"
);
$path
=
\OC\Files\Filesystem
::
getPath
(
$id
);
error_log
(
"new path:
$path
"
);
}
list
(
$uid
,
$filename
)
=
self
::
getUidAndFilename
(
$filename
);
$files_view
=
new
\OC\Files\View
(
'/'
.
$uid
.
'/files'
);
$users_view
=
new
\OC\Files\View
(
'/'
.
$uid
);
//check if source file already exist as version to avoid recursions.
// todo does this check work?
if
(
$users_view
->
file_exists
(
$filename
))
{
return
false
;
}
// check if filename is a directory
if
(
$files_view
->
is_dir
(
$filename
))
{
return
false
;
...
...
@@ -116,10 +94,10 @@ class Storage {
*/
public
static
function
delete
(
$filename
)
{
list
(
$uid
,
$filename
)
=
self
::
getUidAndFilename
(
$filename
);
$versions_fileview
=
new
\OC
_
Files
ystem
View
(
'/'
.
$uid
.
'/files_versions'
);
$versions_fileview
=
new
\OC
\
Files
\
View
(
'/'
.
$uid
.
'/files_versions'
);
$abs_path
=
\OCP\Config
::
getSystemValue
(
'datadirectory'
)
.
$versions_fileview
->
getAbsolutePath
(
''
)
.
$filename
.
'.v'
;
if
(
(
$versions
=
self
::
getVersions
(
$filename
))
)
{
if
(
(
$versions
=
self
::
getVersions
(
$uid
,
$filename
))
)
{
if
(
(
$versionsSize
=
\OCP\Config
::
getAppValue
(
'files_versions'
,
'size'
))
===
null
)
{
$versionsSize
=
self
::
calculateSize
(
$uid
);
}
...
...
@@ -137,16 +115,15 @@ class Storage {
public
static
function
rename
(
$oldpath
,
$newpath
)
{
list
(
$uid
,
$oldpath
)
=
self
::
getUidAndFilename
(
$oldpath
);
list
(
$uidn
,
$newpath
)
=
self
::
getUidAndFilename
(
$newpath
);
$versions_view
=
new
\OC
_
Files
ystem
View
(
'/'
.
$uid
.
'/files_versions'
);
$files_view
=
new
\OC
_
Files
ystem
View
(
'/'
.
$uid
.
'/files'
);
$versions_view
=
new
\OC
\
Files
\
View
(
'/'
.
$uid
.
'/files_versions'
);
$files_view
=
new
\OC
\
Files
\
View
(
'/'
.
$uid
.
'/files'
);
$abs_newpath
=
\OCP\Config
::
getSystemValue
(
'datadirectory'
)
.
$versions_view
->
getAbsolutePath
(
''
)
.
$newpath
;
if
(
$files_view
->
is_dir
(
$oldpath
)
&&
$versions_view
->
is_dir
(
$oldpath
)
)
{
$versions_view
->
rename
(
$oldpath
,
$newpath
);
}
else
if
(
(
$versions
=
Storage
::
getVersions
(
$oldpath
))
)
{
}
else
if
(
(
$versions
=
Storage
::
getVersions
(
$uid
,
$oldpath
))
)
{
$info
=
pathinfo
(
$abs_newpath
);
if
(
!
file_exists
(
$info
[
'dirname'
]))
mkdir
(
$info
[
'dirname'
],
0750
,
true
);
$versions
=
Storage
::
getVersions
(
$oldpath
);
foreach
(
$versions
as
$v
)
{
$versions_view
->
rename
(
$oldpath
.
'.v'
.
$v
[
'version'
],
$newpath
.
'.v'
.
$v
[
'version'
]);
}
...
...
@@ -187,14 +164,14 @@ class Storage {
/**
* @brief get a list of all available versions of a file in descending chronological order
* @param $uid user id from the owner of the file
* @param $filename file to find versions of, relative to the user files dir
* @param $count number of versions to return
* @returns array
*/
public
static
function
getVersions
(
$filename
,
$count
=
0
)
{
public
static
function
getVersions
(
$uid
,
$filename
,
$count
=
0
)
{
if
(
\OCP\Config
::
getSystemValue
(
'files_versions'
,
Storage
::
DEFAULTENABLED
)
==
'true'
)
{
list
(
$uid
,
$filename
)
=
self
::
getUidAndFilename
(
$filename
);
$versions_fileview
=
new
\OC\Files\View
(
'/'
.
\OCP\User
::
getUser
()
.
'/files_versions'
);
$versions_fileview
=
new
\OC\Files\View
(
'/'
.
$uid
.
'/files_versions'
);
$versionsName
=
\OCP\Config
::
getSystemValue
(
'datadirectory'
)
.
$versions_fileview
->
getAbsolutePath
(
$filename
);
$versions
=
array
();
...
...
@@ -203,7 +180,7 @@ class Storage {
sort
(
$matches
);
$files_view
=
new
\OC
_
Files
ystem
View
(
'/'
.
$uid
.
'/files'
);
$files_view
=
new
\OC
\
Files
\
View
(
'/'
.
$uid
.
'/files'
);
$local_file
=
$files_view
->
getLocalFile
(
$filename
);
$local_file_md5
=
\md5_file
(
$local_file
);
...
...
@@ -254,7 +231,7 @@ class Storage {
*/
private
static
function
calculateSize
(
$uid
)
{
if
(
\OCP\Config
::
getSystemValue
(
'files_versions'
,
Storage
::
DEFAULTENABLED
)
==
'true'
)
{
$versions_fileview
=
new
\OC
_
Files
ystem
View
(
'/'
.
$uid
.
'/files_versions'
);
$versions_fileview
=
new
\OC
\
Files
\
View
(
'/'
.
$uid
.
'/files_versions'
);
$versionsRoot
=
\OCP\Config
::
getSystemValue
(
'datadirectory'
)
.
$versions_fileview
->
getAbsolutePath
(
''
);
$iterator
=
new
\RecursiveIteratorIterator
(
new
\RecursiveDirectoryIterator
(
$versionsRoot
),
\RecursiveIteratorIterator
::
CHILD_FIRST
);
...
...
@@ -279,7 +256,7 @@ class Storage {
*/
private
static
function
getAllVersions
(
$uid
)
{
if
(
\OCP\Config
::
getSystemValue
(
'files_versions'
,
Storage
::
DEFAULTENABLED
)
==
'true'
)
{
$versions_fileview
=
new
\OC
_
Files
ystem
View
(
'/'
.
$uid
.
'/files_versions'
);
$versions_fileview
=
new
\OC
\
Files
\
View
(
'/'
.
$uid
.
'/files_versions'
);
$versionsRoot
=
\OCP\Config
::
getSystemValue
(
'datadirectory'
)
.
$versions_fileview
->
getAbsolutePath
(
''
);
$iterator
=
new
\RecursiveIteratorIterator
(
new
\RecursiveDirectoryIterator
(
$versionsRoot
),
\RecursiveIteratorIterator
::
CHILD_FIRST
);
...
...
@@ -325,7 +302,7 @@ class Storage {
private
static
function
expire
(
$filename
,
$versionsSize
=
null
)
{
if
(
\OCP\Config
::
getSystemValue
(
'files_versions'
,
Storage
::
DEFAULTENABLED
)
==
'true'
)
{
list
(
$uid
,
$filename
)
=
self
::
getUidAndFilename
(
$filename
);
$versions_fileview
=
new
\OC
_
Files
ystem
View
(
'/'
.
$uid
.
'/files_versions'
);
$versions_fileview
=
new
\OC
\
Files
\
View
(
'/'
.
$uid
.
'/files_versions'
);
// get available disk space for user
$quota
=
\OCP\Util
::
computerFileSize
(
\OC_Preferences
::
getValue
(
$uid
,
'files'
,
'quota'
));
...
...
@@ -344,7 +321,7 @@ class Storage {
}
// calculate available space for version history
$files_view
=
new
\OC
_
Files
ystem
View
(
'/'
.
$uid
.
'/files'
);
$files_view
=
new
\OC
\
Files
\
View
(
'/'
.
$uid
.
'/files'
);
$rootInfo
=
$files_view
->
getFileInfo
(
'/'
);
$free
=
$quota
-
$rootInfo
[
'size'
];
// remaining free space for user
if
(
$free
>
0
)
{
...
...
@@ -360,7 +337,7 @@ class Storage {
$versions_by_file
=
$result
[
'by_file'
];
$all_versions
=
$result
[
'all'
];
}
else
{
$all_versions
=
Storage
::
getVersions
(
$filename
);
$all_versions
=
Storage
::
getVersions
(
$uid
,
$filename
);
$versions_by_file
[
$filename
]
=
$all_versions
;
}
...
...
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