Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
OLAT CI-CD Testing Project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Contributor 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
Lars Oliver Dam
OLAT CI-CD Testing Project
Commits
2bf23ed5
Commit
2bf23ed5
authored
6 years ago
by
srosse
Browse files
Options
Downloads
Patches
Plain Diff
OO-3742: fix unzip of a file which already exists in the same folder
parent
335da26b
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
src/main/java/org/olat/core/commons/modules/bc/commands/CmdUnzip.java
+30
-3
30 additions, 3 deletions
...a/org/olat/core/commons/modules/bc/commands/CmdUnzip.java
with
30 additions
and
3 deletions
src/main/java/org/olat/core/commons/modules/bc/commands/CmdUnzip.java
+
30
−
3
View file @
2bf23ed5
...
@@ -48,6 +48,7 @@ import org.olat.core.gui.translator.Translator;
...
@@ -48,6 +48,7 @@ import org.olat.core.gui.translator.Translator;
import
org.olat.core.id.Identity
;
import
org.olat.core.id.Identity
;
import
org.olat.core.id.Roles
;
import
org.olat.core.id.Roles
;
import
org.olat.core.logging.AssertException
;
import
org.olat.core.logging.AssertException
;
import
org.olat.core.util.StringHelper
;
import
org.olat.core.util.ZipUtil
;
import
org.olat.core.util.ZipUtil
;
import
org.olat.core.util.vfs.Quota
;
import
org.olat.core.util.vfs.Quota
;
import
org.olat.core.util.vfs.VFSConstants
;
import
org.olat.core.util.vfs.VFSConstants
;
...
@@ -68,11 +69,12 @@ public class CmdUnzip extends BasicController implements FolderCommand {
...
@@ -68,11 +69,12 @@ public class CmdUnzip extends BasicController implements FolderCommand {
super
(
ureq
,
wControl
);
super
(
ureq
,
wControl
);
}
}
@Override
public
Controller
execute
(
FolderComponent
folderComponent
,
UserRequest
ureq
,
WindowControl
wContr
,
Translator
trans
)
{
public
Controller
execute
(
FolderComponent
folderComponent
,
UserRequest
ureq
,
WindowControl
wContr
,
Translator
trans
)
{
this
.
translator
=
trans
;
this
.
translator
=
trans
;
FileSelection
selection
=
new
FileSelection
(
ureq
,
folderComponent
.
getCurrentContainerPath
());
FileSelection
selection
=
new
FileSelection
(
ureq
,
folderComponent
.
getCurrentContainerPath
());
VFSContainer
currentContainer
=
folderComponent
.
getCurrentContainer
();
VFSContainer
currentContainer
=
folderComponent
.
getCurrentContainer
();
if
(!
(
currentContainer
.
canWrite
()
=
=
VFSConstants
.
YES
)
)
if
(
currentContainer
.
canWrite
()
!
=
VFSConstants
.
YES
)
throw
new
AssertException
(
"Cannot unzip to folder. Writing denied."
);
throw
new
AssertException
(
"Cannot unzip to folder. Writing denied."
);
//check if command is executed on a file containing invalid filenames or paths - checks if the resulting folder has a valid name
//check if command is executed on a file containing invalid filenames or paths - checks if the resulting folder has a valid name
...
@@ -81,7 +83,7 @@ public class CmdUnzip extends BasicController implements FolderCommand {
...
@@ -81,7 +83,7 @@ public class CmdUnzip extends BasicController implements FolderCommand {
return
null
;
return
null
;
}
}
List
<
String
>
lockedFiles
=
new
ArrayList
<
String
>();
List
<
String
>
lockedFiles
=
new
ArrayList
<>();
for
(
String
sItem:
selection
.
getFiles
())
{
for
(
String
sItem:
selection
.
getFiles
())
{
VFSItem
vfsItem
=
currentContainer
.
resolve
(
sItem
);
VFSItem
vfsItem
=
currentContainer
.
resolve
(
sItem
);
if
(
vfsItem
instanceof
VFSLeaf
)
{
if
(
vfsItem
instanceof
VFSLeaf
)
{
...
@@ -181,7 +183,19 @@ public class CmdUnzip extends BasicController implements FolderCommand {
...
@@ -181,7 +183,19 @@ public class CmdUnzip extends BasicController implements FolderCommand {
VFSContainer
zipContainer
=
currentContainer
.
createChildContainer
(
sZipContainer
);
VFSContainer
zipContainer
=
currentContainer
.
createChildContainer
(
sZipContainer
);
if
(
zipContainer
==
null
)
{
if
(
zipContainer
==
null
)
{
if
(
versioning
)
{
if
(
versioning
)
{
zipContainer
=(
VFSContainer
)
currentContainer
.
resolve
(
sZipContainer
);
VFSItem
resolvedItem
=
currentContainer
.
resolve
(
sZipContainer
);
if
(
resolvedItem
instanceof
VFSContainer
)
{
zipContainer
=
(
VFSContainer
)
resolvedItem
;
}
else
{
String
numberedFilename
=
findContainerName
(
currentContainer
,
sZipContainer
);
if
(
StringHelper
.
containsNonWhitespace
(
numberedFilename
))
{
zipContainer
=
currentContainer
.
createChildContainer
(
numberedFilename
);
}
if
(
zipContainer
==
null
)
{
// we try our best
wControl
.
setError
(
translator
.
translate
(
"unzip.alreadyexists"
,
new
String
[]
{
sZipContainer
}));
return
false
;
}
}
}
else
{
}
else
{
// folder already exists... issue warning
// folder already exists... issue warning
wControl
.
setError
(
translator
.
translate
(
"unzip.alreadyexists"
,
new
String
[]
{
sZipContainer
}));
wControl
.
setError
(
translator
.
translate
(
"unzip.alreadyexists"
,
new
String
[]
{
sZipContainer
}));
...
@@ -212,6 +226,19 @@ public class CmdUnzip extends BasicController implements FolderCommand {
...
@@ -212,6 +226,19 @@ public class CmdUnzip extends BasicController implements FolderCommand {
}
}
return
true
;
return
true
;
}
}
private
String
findContainerName
(
VFSContainer
container
,
String
filename
)
{
String
newName
=
filename
;
VFSItem
newFile
=
container
.
resolve
(
newName
);
for
(
int
count
=
1
;
newFile
!=
null
&&
count
<
999
;
count
++)
{
newName
=
filename
+
"_"
+
count
;
newFile
=
container
.
resolve
(
newName
);
}
if
(
newFile
==
null
)
{
return
newName
;
}
return
null
;
}
@Override
@Override
public
int
getStatus
()
{
public
int
getStatus
()
{
...
...
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