Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
fuzzBackEnd
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
钱炳权
fuzzBackEnd
Commits
0745a33d
Commit
0745a33d
authored
Apr 22, 2024
by
钱炳权
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test
parent
c96a10bd
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
48 additions
and
20 deletions
+48
-20
KittyServerMessageController.java
...fuzzControll/controller/KittyServerMessageController.java
+0
-1
BaseException.java
...ava/com/example/fuzzControll/exception/BaseException.java
+3
-0
CmdException.java
...java/com/example/fuzzControll/exception/CmdException.java
+5
-1
SeedFileService.java
...ava/com/example/fuzzControll/service/SeedFileService.java
+1
-1
SeedFileServiceImpl.java
...xample/fuzzControll/service/impl/SeedFileServiceImpl.java
+33
-13
CmdTools.java
...rc/main/java/com/example/fuzzControll/tools/CmdTools.java
+2
-2
FileTools.java
...c/main/java/com/example/fuzzControll/tools/FileTools.java
+4
-2
No files found.
fuzzbackend/src/main/java/com/example/fuzzControll/controller/KittyServerMessageController.java
View file @
0745a33d
...
...
@@ -34,7 +34,6 @@ public class KittyServerMessageController {
/**
* 获取服务器templateInfo信息
*/
//todo first
@RequestMapping
(
value
=
"/templateInfo"
,
method
=
RequestMethod
.
GET
)
public
AjaxResult
getTemplateInfo
(
)
{
try
{
...
...
fuzzbackend/src/main/java/com/example/fuzzControll/exception/BaseException.java
View file @
0745a33d
...
...
@@ -15,6 +15,9 @@ public class BaseException extends RuntimeException{
*/
private
String
module
;
public
BaseException
()
{
}
public
BaseException
(
String
defaultMessage
,
String
module
)
{
this
.
defaultMessage
=
defaultMessage
;
this
.
module
=
module
;
...
...
fuzzbackend/src/main/java/com/example/fuzzControll/exception/CmdException.java
View file @
0745a33d
...
...
@@ -3,8 +3,12 @@ package com.example.fuzzControll.exception;
/**
* cmd运行异常
*/
public
class
CmdException
extends
BaseException
{
public
class
CmdException
extends
BaseException
{
private
static
final
long
serialVersionUID
=
1L
;
public
CmdException
()
{
}
public
CmdException
(
String
defaultMessage
)
{
super
(
defaultMessage
,
"cmd"
);
}
...
...
fuzzbackend/src/main/java/com/example/fuzzControll/service/SeedFileService.java
View file @
0745a33d
...
...
@@ -10,5 +10,5 @@ public interface SeedFileService {
void
delFile
(
String
fileName
);
void
upload
(
MultipartFile
file
);
int
getSeedFileCount
();
int
getSeedFileCount
(
String
msg
);
}
fuzzbackend/src/main/java/com/example/fuzzControll/service/impl/SeedFileServiceImpl.java
View file @
0745a33d
...
...
@@ -23,27 +23,42 @@ public class SeedFileServiceImpl implements SeedFileService {
@Override
public
List
<
String
>
getSeedFiles
()
throws
CmdException
{
return
cmdTools
.
runCmd
(
CmdConstent
.
GET_FILE_NAME
+
properties
.
getSeedPath
());
return
cmdTools
.
runCmd
(
CmdConstent
.
GET_FILE_NAME
+
properties
.
getSeedPath
()
,
"getSeedFiles"
);
}
//todo 同步修改可能会出现问题
@Override
public
void
delFile
(
String
fileName
)
throws
CmdException
{
int
fileCountBefore
=
getSeedFileCount
();
cmdTools
.
runCmd
(
CmdConstent
.
DELETE_FILE
+
properties
.
getSeedPath
()
+
"/"
+
fileName
);
int
fileCountAfter
=
getSeedFileCount
();
int
fileCountBefore
=
0
;
int
fileCountAfter
=
0
;
try
{
fileCountBefore
=
getSeedFileCount
(
"delFile before."
);
cmdTools
.
runCmd
(
CmdConstent
.
DELETE_FILE
+
properties
.
getSeedPath
()
+
"/"
+
fileName
,
"delFile"
);
fileCountAfter
=
getSeedFileCount
(
"delFile after."
);
}
catch
(
CmdException
e
)
{
throw
new
CmdException
(
e
.
getMessage
());
}
if
(
fileCountAfter
==
fileCountBefore
){
throw
new
CmdException
(
"
delete cmd error !The file has not changed
."
);
throw
new
CmdException
(
"
Delete unsuccess ! The file has not changed .Attempt to change permissions
."
);
}
}
@Override
public
void
upload
(
MultipartFile
file
)
throws
FileException
{
int
fileCountBefore
=
getSeedFileCount
();
fileTools
.
load
(
file
);
int
fileCountAfter
=
getSeedFileCount
();
public
void
upload
(
MultipartFile
file
)
throws
FileException
,
CmdException
{
int
fileCountBefore
=
0
;
int
fileCountAfter
=
0
;
try
{
fileCountBefore
=
getSeedFileCount
(
"upload before."
);
fileTools
.
load
(
file
);
fileCountAfter
=
getSeedFileCount
(
"upload after."
);
}
catch
(
CmdException
e
)
{
throw
new
CmdException
(
e
.
getMessage
());
}
catch
(
FileException
e
){
throw
new
FileException
(
e
.
getMessage
());
}
if
(
fileCountAfter
==
fileCountBefore
){
throw
new
CmdException
(
"upload file error !The file failed to be submitted
."
);
throw
new
FileException
(
"upload file error !The file failed to be submitted.Attempt to change permissions
."
);
}
}
...
...
@@ -52,9 +67,14 @@ public class SeedFileServiceImpl implements SeedFileService {
* 获取种子文件目录下文件数量
*/
@Override
public
int
getSeedFileCount
()
throws
CmdException
{
List
<
String
>
files
=
cmdTools
.
runCmd
(
CmdConstent
.
GET_FILE_NAME
+
properties
.
getSeedPath
());
int
count
=
files
.
size
();
public
int
getSeedFileCount
(
String
msg
)
throws
CmdException
{
int
count
=
0
;
try
{
List
<
String
>
files
=
cmdTools
.
runCmd
(
CmdConstent
.
GET_FILE_NAME
+
properties
.
getSeedPath
(),
"getSeedFileCount"
);
count
=
files
.
size
();
}
catch
(
CmdException
e
)
{
throw
new
CmdException
(
e
.
getMessage
()+
" when "
+
msg
);
}
return
count
;
}
}
fuzzbackend/src/main/java/com/example/fuzzControll/tools/CmdTools.java
View file @
0745a33d
...
...
@@ -24,7 +24,7 @@ public class CmdTools {
/**
* 运行不需要后台运行cmd
*/
public
List
<
String
>
runCmd
(
String
cmd
)
throws
CmdException
{
public
List
<
String
>
runCmd
(
String
cmd
,
String
caller
)
throws
CmdException
{
List
<
String
>
result
=
new
ArrayList
<
String
>();
try
{
Process
process
=
Runtime
.
getRuntime
().
exec
(
cmd
);
...
...
@@ -32,7 +32,7 @@ public class CmdTools {
printMessage
(
process
.
getErrorStream
(),
new
ArrayList
<
String
>());
process
.
waitFor
();
}
catch
(
Exception
e
)
{
throw
new
CmdException
(
"run delete or search cmd error
!"
);
throw
new
CmdException
(
caller
+
" run cmd failed
!"
);
}
return
result
;
...
...
fuzzbackend/src/main/java/com/example/fuzzControll/tools/FileTools.java
View file @
0745a33d
...
...
@@ -3,6 +3,7 @@ package com.example.fuzzControll.tools;
import
com.example.fuzzControll.conf.SpringContextUtil
;
import
com.example.fuzzControll.conf.SeedProperties
;
import
com.example.fuzzControll.exception.FileException
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.web.multipart.MultipartFile
;
import
java.io.BufferedInputStream
;
...
...
@@ -10,24 +11,25 @@ import java.io.BufferedOutputStream;
import
java.io.FileOutputStream
;
import
java.io.InputStream
;
@Slf4j
public
class
FileTools
{
SeedProperties
properties
=
(
SeedProperties
)
SpringContextUtil
.
getBean
(
"seedProperties"
);
public
void
load
(
MultipartFile
file
)
throws
FileException
{
if
(
file
==
null
)
{
if
(
file
==
null
)
{
throw
new
FileException
(
"upload file is null !"
);
}
try
(
InputStream
inputStream
=
file
.
getInputStream
();
FileOutputStream
outputStream
=
new
FileOutputStream
(
properties
.
getSeedPath
()
+
"/"
+
file
.
getOriginalFilename
());)
{
BufferedInputStream
bufferedInputStream
=
new
BufferedInputStream
(
inputStream
);
BufferedOutputStream
bufferedOutputStream
=
new
BufferedOutputStream
(
outputStream
);
byte
[]
buffer
=
new
byte
[
1024
];
int
bytesRead
;
while
((
bytesRead
=
bufferedInputStream
.
read
(
buffer
))
!=
-
1
)
{
bufferedOutputStream
.
write
(
buffer
,
0
,
bytesRead
);
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
new
FileException
(
"write file error !"
);
}
...
...
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