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
ea246d05
Commit
ea246d05
authored
11 years ago
by
Andreas Fischer
Browse files
Options
Downloads
Patches
Plain Diff
Use "file size" instead of "filesize", then also apply camel case.
parent
0417e521
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/largefilehelper.php
+24
-24
24 additions, 24 deletions
lib/private/largefilehelper.php
tests/lib/largefilehelpergetfilesize.php
+16
-16
16 additions, 16 deletions
tests/lib/largefilehelpergetfilesize.php
with
40 additions
and
40 deletions
lib/private/largefilehelper.php
+
24
−
24
View file @
ea246d05
...
...
@@ -62,7 +62,7 @@ class LargeFileHelper {
}
/**
* @brief Tries to get the
file
size of a file via various workarounds that
* @brief Tries to get the size of a file via various workarounds that
* even work for large files on 32-bit platforms.
*
* @param string $filename Path to the file.
...
...
@@ -70,31 +70,31 @@ class LargeFileHelper {
* @return null|int|float Number of bytes as number (float or int) or
* null on failure.
*/
public
function
getFile
s
ize
(
$filename
)
{
$file
s
ize
=
$this
->
getFile
s
izeViaCurl
(
$filename
);
if
(
!
is_null
(
$file
s
ize
))
{
return
$file
s
ize
;
public
function
getFile
S
ize
(
$filename
)
{
$file
S
ize
=
$this
->
getFile
S
izeViaCurl
(
$filename
);
if
(
!
is_null
(
$file
S
ize
))
{
return
$file
S
ize
;
}
$file
s
ize
=
$this
->
getFile
s
izeViaCOM
(
$filename
);
if
(
!
is_null
(
$file
s
ize
))
{
return
$file
s
ize
;
$file
S
ize
=
$this
->
getFile
S
izeViaCOM
(
$filename
);
if
(
!
is_null
(
$file
S
ize
))
{
return
$file
S
ize
;
}
$file
s
ize
=
$this
->
getFile
s
izeViaExec
(
$filename
);
if
(
!
is_null
(
$file
s
ize
))
{
return
$file
s
ize
;
$file
S
ize
=
$this
->
getFile
S
izeViaExec
(
$filename
);
if
(
!
is_null
(
$file
S
ize
))
{
return
$file
S
ize
;
}
return
$this
->
getFile
s
izeNative
(
$filename
);
return
$this
->
getFile
S
izeNative
(
$filename
);
}
/**
* @brief Tries to get the
file
size of a file via a CURL HEAD request.
* @brief Tries to get the size of a file via a CURL HEAD request.
*
* @param string $filename Path to the file.
*
* @return null|int|float Number of bytes as number (float or int) or
* null on failure.
*/
public
function
getFile
s
izeViaCurl
(
$filename
)
{
public
function
getFile
S
izeViaCurl
(
$filename
)
{
if
(
function_exists
(
'curl_init'
))
{
$ch
=
curl_init
(
"file://
$filename
"
);
curl_setopt
(
$ch
,
CURLOPT_NOBODY
,
true
);
...
...
@@ -114,14 +114,14 @@ class LargeFileHelper {
}
/**
* @brief Tries to get the
file
size of a file via the Windows DOM extension.
* @brief Tries to get the size of a file via the Windows DOM extension.
*
* @param string $filename Path to the file.
*
* @return null|int|float Number of bytes as number (float or int) or
* null on failure.
*/
public
function
getFile
s
izeViaCOM
(
$filename
)
{
public
function
getFile
S
izeViaCOM
(
$filename
)
{
if
(
class_exists
(
'COM'
))
{
$fsobj
=
new
\COM
(
"Scripting.FileSystemObject"
);
$file
=
$fsobj
->
GetFile
(
$filename
);
...
...
@@ -131,14 +131,14 @@ class LargeFileHelper {
}
/**
* @brief Tries to get the
file
size of a file via an exec() call.
* @brief Tries to get the size of a file via an exec() call.
*
* @param string $filename Path to the file.
*
* @return null|int|float Number of bytes as number (float or int) or
* null on failure.
*/
public
function
getFile
s
izeViaExec
(
$filename
)
{
public
function
getFile
S
izeViaExec
(
$filename
)
{
if
(
\OC_Helper
::
is_function_enabled
(
'exec'
))
{
$os
=
strtolower
(
php_uname
(
's'
));
$arg
=
escapeshellarg
(
$filename
);
...
...
@@ -160,19 +160,19 @@ class LargeFileHelper {
}
/**
* @brief Gets the
filesiz
e via a filesize() call and converts
negative
* signed int to positive float. As the result of filesize()
will
* wrap around after a filesize of 2^32 bytes = 4 GiB, this
should
* only be used as a last resort.
* @brief Gets the
size of a fil
e via a filesize() call and converts
*
negative
signed int to positive float. As the result of filesize()
*
will
wrap around after a file
size of 2^32 bytes = 4 GiB, this
*
should
only be used as a last resort.
*
* @param string $filename Path to the file.
*
* @return int|float Number of bytes as number (float or int).
*/
public
function
getFile
s
izeNative
(
$filename
)
{
public
function
getFile
S
izeNative
(
$filename
)
{
$result
=
filesize
(
$filename
);
if
(
$result
<
0
)
{
// For filesizes between 2 GiB and 4 GiB, filesize() will return a
// For file
sizes between 2 GiB and 4 GiB, filesize() will return a
// negative int, as the PHP data type int is signed. Interpret the
// returned int as an unsigned integer and put it into a float.
return
(
float
)
sprintf
(
'%u'
,
$result
);
...
...
This diff is collapsed.
Click to expand it.
tests/lib/largefilehelpergetfilesize.php
+
16
−
16
View file @
ea246d05
...
...
@@ -9,61 +9,61 @@
namespace
Test
;
/**
* Tests whether LargeFileHelper is able to determine filesize at all.
* Tests whether LargeFileHelper is able to determine file
size at all.
* Large files are not considered yet.
*/
class
LargeFileHelperGetFile
s
ize
extends
\PHPUnit_Framework_TestCase
{
class
LargeFileHelperGetFile
S
ize
extends
\PHPUnit_Framework_TestCase
{
protected
$filename
;
protected
$file
s
ize
;
protected
$file
S
ize
;
protected
$helper
;
public
function
setUp
()
{
parent
::
setUp
();
$this
->
filename
=
__DIR__
.
'/../data/data.tar.gz'
;
$this
->
file
s
ize
=
4195
;
$this
->
file
S
ize
=
4195
;
$this
->
helper
=
new
\OC\LargeFileHelper
;
}
public
function
testGetFile
s
izeViaCurl
()
{
public
function
testGetFile
S
izeViaCurl
()
{
if
(
!
extension_loaded
(
'curl'
))
{
$this
->
markTestSkipped
(
'The PHP curl extension is required for this test.'
);
}
$this
->
assertSame
(
$this
->
file
s
ize
,
$this
->
helper
->
getFile
s
izeViaCurl
(
$this
->
filename
)
$this
->
file
S
ize
,
$this
->
helper
->
getFile
S
izeViaCurl
(
$this
->
filename
)
);
}
public
function
testGetFile
s
izeViaCOM
()
{
public
function
testGetFile
S
izeViaCOM
()
{
if
(
!
extension_loaded
(
'COM'
))
{
$this
->
markTestSkipped
(
'The PHP Windows COM extension is required for this test.'
);
}
$this
->
assertSame
(
$this
->
file
s
ize
,
$this
->
helper
->
getFile
s
izeViaDOM
(
$this
->
filename
)
$this
->
file
S
ize
,
$this
->
helper
->
getFile
S
izeViaDOM
(
$this
->
filename
)
);
}
public
function
testGetFile
s
izeViaExec
()
{
public
function
testGetFile
S
izeViaExec
()
{
if
(
!
\OC_Helper
::
is_function_enabled
(
'exec'
))
{
$this
->
markTestSkipped
(
'The exec() function needs to be enabled for this test.'
);
}
$this
->
assertSame
(
$this
->
file
s
ize
,
$this
->
helper
->
getFile
s
izeViaExec
(
$this
->
filename
)
$this
->
file
S
ize
,
$this
->
helper
->
getFile
S
izeViaExec
(
$this
->
filename
)
);
}
public
function
testGetFile
s
izeNative
()
{
public
function
testGetFile
S
izeNative
()
{
$this
->
assertSame
(
$this
->
file
s
ize
,
$this
->
helper
->
getFile
s
izeNative
(
$this
->
filename
)
$this
->
file
S
ize
,
$this
->
helper
->
getFile
S
izeNative
(
$this
->
filename
)
);
}
}
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