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
318d024c
Commit
318d024c
authored
13 years ago
by
Robin Appelman
Browse files
Options
Downloads
Patches
Plain Diff
show size of folders in filebrowser
parent
1495ec0f
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
files/templates/index.php
+1
-1
1 addition, 1 deletion
files/templates/index.php
lib/files.php
+1
-0
1 addition, 0 deletions
lib/files.php
lib/filestorage.php
+69
-1
69 additions, 1 deletion
lib/filestorage.php
with
71 additions
and
2 deletions
files/templates/index.php
+
1
−
1
View file @
318d024c
...
...
@@ -33,7 +33,7 @@
<tr>
<td
class=
"selection"
><input
type=
"checkbox"
/></td>
<td
class=
"filename"
><a
style=
"background-image:url(
<?php
if
(
$file
[
"type"
]
==
"dir"
)
echo
mimetype_icon
(
"dir"
);
else
echo
mimetype_icon
(
$file
[
"mime"
]);
?>
)"
href=
"
<?php
if
(
$file
[
"type"
]
==
"dir"
)
echo
link_to
(
"files"
,
"index.php?dir="
.
$file
[
"directory"
]
.
"/"
.
$file
[
"name"
]);
else
echo
link_to
(
"files"
,
"download.php?file="
.
$file
[
"directory"
]
.
"/"
.
$file
[
"name"
]);
?>
"
title=
""
>
<?php
echo
$file
[
"name"
];
?>
</a></td>
<td
class=
"filesize"
>
<?php
if
(
$file
[
"type"
]
!=
"dir"
)
echo
human_file_size
(
$file
[
"size"
]);
?>
</td>
<td
class=
"filesize"
>
<?php
echo
human_file_size
(
$file
[
"size"
]);
?>
</td>
<td
class=
"date"
>
<?php
if
(
$file
[
"type"
]
!=
"dir"
)
echo
$file
[
"date"
];
?>
</td>
<td
class=
"fileaction"
><a
href=
""
title=
""
><img
src=
"images/drop-arrow.png"
alt=
"+"
/></a></td>
</tr>
...
...
This diff is collapsed.
Click to expand it.
lib/files.php
+
1
−
0
View file @
318d024c
...
...
@@ -64,6 +64,7 @@ class OC_FILES {
$file
[
'directory'
]
=
$directory
;
$stat
=
OC_FILESYSTEM
::
stat
(
$directory
.
'/'
.
$filename
);
$file
=
array_merge
(
$file
,
$stat
);
$file
[
'size'
]
=
OC_FILESYSTEM
::
filesize
(
$directory
.
'/'
.
$filename
);
$file
[
'mime'
]
=
OC_FILES
::
getMimeType
(
$directory
.
'/'
.
$filename
);
$file
[
'readable'
]
=
OC_FILESYSTEM
::
is_readable
(
$directory
.
'/'
.
$filename
);
$file
[
'writeable'
]
=
OC_FILESYSTEM
::
is_writeable
(
$directory
.
'/'
.
$filename
);
...
...
This diff is collapsed.
Click to expand it.
lib/filestorage.php
+
69
−
1
View file @
318d024c
...
...
@@ -124,7 +124,11 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{
return
$filetype
;
}
public
function
filesize
(
$path
){
return
filesize
(
$this
->
datadir
.
$path
);
if
(
$this
->
is_dir
(
$path
)){
return
$this
->
getFolderSize
(
$path
);
}
else
{
return
filesize
(
$this
->
datadir
.
$path
);
}
}
public
function
is_readable
(
$path
){
return
is_readable
(
$this
->
datadir
.
$path
);
...
...
@@ -159,6 +163,7 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{
public
function
file_put_contents
(
$path
,
$data
){
if
(
$return
=
file_put_contents
(
$this
->
datadir
.
$path
,
$data
)){
$this
->
notifyObservers
(
$path
,
OC_FILEACTION_WRITE
);
$this
->
clearFolderSizeCache
(
$path
);
}
}
public
function
unlink
(
$path
){
...
...
@@ -197,11 +202,13 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{
case
'x+'
:
case
'a+'
:
$this
->
notifyObservers
(
$path
,
OC_FILEACTION_READ
|
OC_FILEACTION_WRITE
);
$this
->
clearFolderSizeCache
(
$path
);
break
;
case
'w'
:
case
'x'
:
case
'a'
:
$this
->
notifyObservers
(
$path
,
OC_FILEACTION_WRITE
);
$this
->
clearFolderSizeCache
(
$path
);
break
;
}
}
...
...
@@ -440,5 +447,66 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{
}
return
$return
;
}
/**
* @brief get the size of folder and it's content
* @param string $path file path
* @return int size of folder and it's content
*/
public
function
getFolderSize
(
$path
){
$query
=
OC_DB
::
prepare
(
"SELECT size FROM *PREFIX*foldersize WHERE path=?"
);
$size
=
$query
->
execute
(
array
(
$path
))
->
fetchAll
();
if
(
count
(
$size
)
>
0
){
// we already the size, just return it
return
$size
[
0
][
'size'
];
}
else
{
//the size of the folder isn't know, calulate it
return
$this
->
calculateFolderSize
(
$path
);
}
}
/**
* @brief calulate the size of folder and it's content and cache it
* @param string $path file path
* @return int size of folder and it's content
*/
public
function
calculateFolderSize
(
$path
){
$size
=
0
;
if
(
$dh
=
$this
->
opendir
(
$path
))
{
while
((
$filename
=
readdir
(
$dh
))
!==
false
)
{
if
(
$filename
!=
'.'
and
$filename
!=
'..'
){
$subFile
=
$path
.
'/'
.
$filename
;
if
(
$this
->
is_file
(
$subFile
)){
$size
+=
$this
->
filesize
(
$subFile
);
}
else
{
$size
+=
$this
->
calculateFolderSize
(
$subFile
);
}
}
}
$query
=
OC_DB
::
prepare
(
"SELECT size FROM *PREFIX*foldersize WHERE path=?"
);
$hasSize
=
$query
->
execute
(
array
(
$path
))
->
fetchAll
();
if
(
count
(
$hasSize
)
>
0
){
// yes, update it
$query
=
OC_DB
::
prepare
(
"UPDATE *PREFIX*foldersize SET size=? WHERE path=?"
);
$result
=
$query
->
execute
(
array
(
$size
,
$path
));
}
else
{
// no insert it
$query
=
OC_DB
::
prepare
(
"INSERT INTO *PREFIX*foldersize VALUES(?,?)"
);
$result
=
$query
->
execute
(
array
(
$path
,
$size
));
}
}
return
$size
;
}
/**
* @brief clear the folder size cache of folders containing a file
* @param string $path
*/
public
function
clearFolderSizeCache
(
$path
){
$path
=
dirname
(
$path
);
$query
=
OC_DB
::
prepare
(
"DELETE FROM *PREFIX*foldersize WHERE path = ?"
);
$result
=
$query
->
execute
(
array
(
$path
));
if
(
$path
!=
'/'
){
$parts
=
explode
(
'/'
);
array_pop
(
$parts
);
$parent
=
implode
(
'/'
,
$parts
);
}
}
}
?>
\ No newline at end of file
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