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
16efd81a
Commit
16efd81a
authored
11 years ago
by
Björn Schießle
Browse files
Options
Downloads
Patches
Plain Diff
first check if file exists before checking the files size
parent
837cefd8
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
apps/files_versions/lib/versions.php
+9
-10
9 additions, 10 deletions
apps/files_versions/lib/versions.php
with
9 additions
and
10 deletions
apps/files_versions/lib/versions.php
+
9
−
10
View file @
16efd81a
...
@@ -48,14 +48,14 @@ class Storage {
...
@@ -48,14 +48,14 @@ class Storage {
/**
/**
* get current size of all versions from a given user
* get current size of all versions from a given user
*
*
* @param $user user who owns the versions
* @param $user user who owns the versions
* @return mixed versions size or false if no versions size is stored
* @return mixed versions size or false if no versions size is stored
*/
*/
private
static
function
getVersionsSize
(
$user
)
{
private
static
function
getVersionsSize
(
$user
)
{
$query
=
\OC_DB
::
prepare
(
'SELECT `size` FROM `*PREFIX*files_versions` WHERE `user`=?'
);
$query
=
\OC_DB
::
prepare
(
'SELECT `size` FROM `*PREFIX*files_versions` WHERE `user`=?'
);
$result
=
$query
->
execute
(
array
(
$user
))
->
fetchAll
();
$result
=
$query
->
execute
(
array
(
$user
))
->
fetchAll
();
if
(
$result
)
{
if
(
$result
)
{
return
$result
[
0
][
'size'
];
return
$result
[
0
][
'size'
];
}
}
...
@@ -64,7 +64,7 @@ class Storage {
...
@@ -64,7 +64,7 @@ class Storage {
/**
/**
* write to the database how much space is in use for versions
* write to the database how much space is in use for versions
*
*
* @param $user owner of the versions
* @param $user owner of the versions
* @param $size size of the versions
* @param $size size of the versions
*/
*/
...
@@ -76,20 +76,20 @@ class Storage {
...
@@ -76,20 +76,20 @@ class Storage {
}
}
$query
->
execute
(
array
(
$size
,
$user
));
$query
->
execute
(
array
(
$size
,
$user
));
}
}
/**
/**
* store a new version of a file.
* store a new version of a file.
*/
*/
public
static
function
store
(
$filename
)
{
public
static
function
store
(
$filename
)
{
if
(
\OCP\Config
::
getSystemValue
(
'files_versions'
,
Storage
::
DEFAULTENABLED
)
==
'true'
)
{
if
(
\OCP\Config
::
getSystemValue
(
'files_versions'
,
Storage
::
DEFAULTENABLED
)
==
'true'
)
{
// if the file gets streamed we need to remove the .part extension
// if the file gets streamed we need to remove the .part extension
// to get the right target
// to get the right target
$ext
=
pathinfo
(
$filename
,
PATHINFO_EXTENSION
);
$ext
=
pathinfo
(
$filename
,
PATHINFO_EXTENSION
);
if
(
$ext
===
'part'
)
{
if
(
$ext
===
'part'
)
{
$filename
=
substr
(
$filename
,
0
,
strlen
(
$filename
)
-
5
);
$filename
=
substr
(
$filename
,
0
,
strlen
(
$filename
)
-
5
);
}
}
list
(
$uid
,
$filename
)
=
self
::
getUidAndFilename
(
$filename
);
list
(
$uid
,
$filename
)
=
self
::
getUidAndFilename
(
$filename
);
$files_view
=
new
\OC\Files\View
(
'/'
.
$uid
.
'/files'
);
$files_view
=
new
\OC\Files\View
(
'/'
.
$uid
.
'/files'
);
...
@@ -104,8 +104,7 @@ class Storage {
...
@@ -104,8 +104,7 @@ class Storage {
// we should have a source file to work with, and the file shouldn't
// we should have a source file to work with, and the file shouldn't
// be empty
// be empty
$fileExists
=
$files_view
->
file_exists
(
$filename
);
$fileExists
=
$files_view
->
file_exists
(
$filename
);
$fileSize
=
$files_view
->
filesize
(
$filename
);
if
(
!
(
$fileExists
&&
$files_view
->
filesize
(
$filename
)
>
0
))
{
if
(
$fileExists
===
false
||
$fileSize
===
0
)
{
return
false
;
return
false
;
}
}
...
@@ -174,7 +173,7 @@ class Storage {
...
@@ -174,7 +173,7 @@ class Storage {
list
(
$uidn
,
$newpath
)
=
self
::
getUidAndFilename
(
$new_path
);
list
(
$uidn
,
$newpath
)
=
self
::
getUidAndFilename
(
$new_path
);
$versions_view
=
new
\OC\Files\View
(
'/'
.
$uid
.
'/files_versions'
);
$versions_view
=
new
\OC\Files\View
(
'/'
.
$uid
.
'/files_versions'
);
$files_view
=
new
\OC\Files\View
(
'/'
.
$uid
.
'/files'
);
$files_view
=
new
\OC\Files\View
(
'/'
.
$uid
.
'/files'
);
// if the file already exists than it was a upload of a existing file
// if the file already exists than it was a upload of a existing file
// over the web interface -> store() is the right function we need here
// over the web interface -> store() is the right function we need here
if
(
$files_view
->
file_exists
(
$newpath
))
{
if
(
$files_view
->
file_exists
(
$newpath
))
{
...
@@ -435,7 +434,7 @@ class Storage {
...
@@ -435,7 +434,7 @@ class Storage {
}
else
{
}
else
{
$quota
=
\OCP\Util
::
computerFileSize
(
$quota
);
$quota
=
\OCP\Util
::
computerFileSize
(
$quota
);
}
}
// make sure that we have the current size of the version history
// make sure that we have the current size of the version history
if
(
$versionsSize
===
null
)
{
if
(
$versionsSize
===
null
)
{
$versionsSize
=
self
::
getVersionsSize
(
$uid
);
$versionsSize
=
self
::
getVersionsSize
(
$uid
);
...
...
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