Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
genotoul-bioinfo
ng6
Commits
22440680
Commit
22440680
authored
Sep 04, 2018
by
Gerald Salin
Browse files
test if directory exist before trying to delete its content to avoid
errors
parent
d25986df
Changes
1
Hide whitespace changes
Inline
Side-by-side
ui/nG6/lib/class.tx_nG6_utils.php
View file @
22440680
...
...
@@ -137,7 +137,6 @@ class tx_nG6_utils {
static
function
purge_directory
(
$user_login
,
$user_pwd
,
$directory
)
{
if
(
$directory
!=
'undefined'
&&
$directory
!=
''
)
{
// And process the directories structure, remove all files except .html ans .png
$connection
=
ssh2_connect
(
'127.0.0.1'
,
22
);
if
(
!
$connection
)
{
return
3
;
...
...
@@ -146,6 +145,20 @@ class tx_nG6_utils {
if
(
!
ssh2_auth_password
(
$connection
,
$user_login
,
$user_pwd
)){
return
2
;
}
$stream
=
ssh2_exec
(
$connection
,
'ls '
.
$directory
.
'/*'
);
$errorStream
=
ssh2_fetch_stream
(
$stream
,
SSH2_STREAM_STDERR
);
// Enable blocking for both streams
stream_set_blocking
(
$errorStream
,
true
);
stream_set_blocking
(
$stream
,
true
);
//if error is raised, $directory does not exist>no problem (in case of an analysis which do not have associated files
if
(
stream_get_contents
(
$errorStream
))
{
// Close the streams
fclose
(
$errorStream
);
fclose
(
$stream
);
return
0
;
}
$stream
=
ssh2_exec
(
$connection
,
'ls '
.
$directory
.
'/* | grep -v -e ".html$" -e ".png$" | xargs rm -f'
);
$errorStream
=
ssh2_fetch_stream
(
$stream
,
SSH2_STREAM_STDERR
);
...
...
@@ -153,8 +166,7 @@ class tx_nG6_utils {
stream_set_blocking
(
$errorStream
,
true
);
stream_set_blocking
(
$stream
,
true
);
// Whichever of the two below commands is listed first will receive its appropriate output. The second command receives nothing
//if error is raised, connected user does not have the right to delete the files
if
(
stream_get_contents
(
$errorStream
))
{
// Close the streams
fclose
(
$errorStream
);
...
...
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