Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
die_coolen_jungs
our_own_cloud_project
Commits
746be98e
Commit
746be98e
authored
Mar 26, 2015
by
Vincent Petry
Browse files
Merge pull request #13654 from oparoz/tmpfile-with-extension
Keep the extension in temp files
parents
d082e372
f890c3ff
Changes
3
Hide whitespace changes
Inline
Side-by-side
lib/private/preview/office.php
View file @
746be98e
...
...
@@ -45,12 +45,16 @@ abstract class Office extends Provider {
shell_exec
(
$exec
);
//create imagick object from pdf
$pdfPreview
=
null
;
try
{
$pdf
=
new
\
imagick
(
$absPath
.
'.pdf'
.
'[0]'
);
list
(
$dirname
,
,
,
$filename
)
=
array_values
(
pathinfo
(
$absPath
)
);
$pdfPreview
=
$dirname
.
'/'
.
$filename
.
'.pdf'
;
$pdf
=
new
\
imagick
(
$pdfPreview
.
'[0]'
);
$pdf
->
setImageFormat
(
'jpg'
);
}
catch
(
\
Exception
$e
)
{
unlink
(
$absPath
);
unlink
(
$
absPath
.
'.pdf'
);
unlink
(
$
pdfPreview
);
\
OC_Log
::
write
(
'core'
,
$e
->
getmessage
(),
\
OC_Log
::
ERROR
);
return
false
;
}
...
...
@@ -59,7 +63,7 @@ abstract class Office extends Provider {
$image
->
loadFromData
(
$pdf
);
unlink
(
$absPath
);
unlink
(
$
absPath
.
'.pdf'
);
unlink
(
$
pdfPreview
);
return
$image
->
valid
()
?
$image
:
false
;
}
...
...
lib/private/tempmanager.php
View file @
746be98e
...
...
@@ -55,6 +55,9 @@ class TempManager implements ITempManager {
}
protected
function
generatePath
(
$postFix
)
{
if
(
$postFix
)
{
$postFix
=
'.'
.
ltrim
(
$postFix
,
'.'
);
}
return
$this
->
tmpBaseDir
.
'/oc_tmp_'
.
md5
(
time
()
.
rand
())
.
$postFix
;
}
...
...
tests/lib/tempmanager.php
View file @
746be98e
...
...
@@ -51,7 +51,7 @@ class TempManager extends \Test\TestCase {
public
function
testGetFile
()
{
$manager
=
$this
->
getManager
();
$file
=
$manager
->
getTemporaryFile
(
'
.
txt'
);
$file
=
$manager
->
getTemporaryFile
(
'txt'
);
$this
->
assertStringEndsWith
(
'.txt'
,
$file
);
$this
->
assertTrue
(
is_file
(
$file
));
$this
->
assertTrue
(
is_writable
(
$file
));
...
...
@@ -73,8 +73,8 @@ class TempManager extends \Test\TestCase {
public
function
testCleanFiles
()
{
$manager
=
$this
->
getManager
();
$file1
=
$manager
->
getTemporaryFile
(
'
.
txt'
);
$file2
=
$manager
->
getTemporaryFile
(
'
.
txt'
);
$file1
=
$manager
->
getTemporaryFile
(
'txt'
);
$file2
=
$manager
->
getTemporaryFile
(
'txt'
);
$this
->
assertTrue
(
file_exists
(
$file1
));
$this
->
assertTrue
(
file_exists
(
$file2
));
...
...
@@ -105,8 +105,8 @@ class TempManager extends \Test\TestCase {
public
function
testCleanOld
()
{
$manager
=
$this
->
getManager
();
$oldFile
=
$manager
->
getTemporaryFile
(
'
.
txt'
);
$newFile
=
$manager
->
getTemporaryFile
(
'
.
txt'
);
$oldFile
=
$manager
->
getTemporaryFile
(
'txt'
);
$newFile
=
$manager
->
getTemporaryFile
(
'txt'
);
$folder
=
$manager
->
getTemporaryFolder
();
$nonOcFile
=
$this
->
baseDir
.
'/foo.txt'
;
file_put_contents
(
$nonOcFile
,
'bar'
);
...
...
@@ -135,7 +135,7 @@ class TempManager extends \Test\TestCase {
$logger
->
expects
(
$this
->
once
())
->
method
(
'warning'
)
->
with
(
$this
->
stringContains
(
'Can not create a temporary file in directory'
));
$this
->
assertFalse
(
$manager
->
getTemporaryFile
(
'
.
txt'
));
$this
->
assertFalse
(
$manager
->
getTemporaryFile
(
'txt'
));
}
public
function
testLogCantCreateFolder
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment