Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
caosdb-server
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue 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
caosdb
Software
caosdb-server
Commits
e67b2654
Unverified
Commit
e67b2654
authored
6 years ago
by
Timm Fitschen
Browse files
Options
Downloads
Patches
Plain Diff
BUG: move directories
parent
c02813fd
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/caosdb/server/utils/FileUtils.java
+19
-3
19 additions, 3 deletions
src/main/java/caosdb/server/utils/FileUtils.java
with
19 additions
and
3 deletions
src/main/java/caosdb/server/utils/FileUtils.java
+
19
−
3
View file @
e67b2654
...
...
@@ -40,6 +40,7 @@ import java.io.IOException;
import
java.io.InputStream
;
import
java.io.InputStreamReader
;
import
java.io.Reader
;
import
java.nio.file.LinkOption
;
import
java.security.MessageDigest
;
import
java.security.NoSuchAlgorithmException
;
import
java.util.Arrays
;
...
...
@@ -290,6 +291,21 @@ public class FileUtils {
}
}
}
private
static
boolean
exists
(
File
file
)
{
return
java
.
nio
.
file
.
Files
.
exists
(
file
.
toPath
(),
LinkOption
.
NOFOLLOW_LINKS
);
}
private
static
void
moveReplace
(
File
file
,
File
target
)
throws
IOException
{
if
(
exists
(
target
))
{
org
.
apache
.
commons
.
io
.
FileUtils
.
forceDelete
(
target
);
}
if
(
java
.
nio
.
file
.
Files
.
isDirectory
(
file
.
toPath
(),
LinkOption
.
NOFOLLOW_LINKS
))
{
org
.
apache
.
commons
.
io
.
FileUtils
.
moveDirectory
(
file
,
target
);
}
else
{
org
.
apache
.
commons
.
io
.
FileUtils
.
moveFile
(
file
,
target
);
}
}
public
static
Undoable
rename
(
final
File
file
,
final
File
target
)
throws
Message
,
IOException
{
final
File
backup
;
...
...
@@ -302,17 +318,17 @@ public class FileUtils {
public
void
cleanUp
()
{}
};
}
if
(
target
.
exists
())
{
if
(
exists
(
target
))
{
// in case this is a update transaction, the old version of the file
// must be stored somewhere until the transaction is done.
final
File
tmp
=
new
File
(
new
File
(
FileSystem
.
getTmp
()),
target
.
getName
()
+
Utils
.
getUID
());
java
.
nio
.
file
.
Files
.
move
(
target
.
toPath
(),
tmp
.
toPath
()
);
moveReplace
(
target
,
tmp
);
backup
=
tmp
;
}
else
{
backup
=
null
;
}
try
{
java
.
nio
.
file
.
Files
.
move
(
file
.
toPath
(),
target
.
toPath
()
);
moveReplace
(
file
,
target
);
return
new
UndoHandler
()
{
private
File
_backup
=
backup
;
...
...
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