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 {
...
@@ -34,7 +34,6 @@ public class KittyServerMessageController {
/**
/**
* 获取服务器templateInfo信息
* 获取服务器templateInfo信息
*/
*/
//todo first
@RequestMapping
(
value
=
"/templateInfo"
,
method
=
RequestMethod
.
GET
)
@RequestMapping
(
value
=
"/templateInfo"
,
method
=
RequestMethod
.
GET
)
public
AjaxResult
getTemplateInfo
(
)
{
public
AjaxResult
getTemplateInfo
(
)
{
try
{
try
{
...
...
fuzzbackend/src/main/java/com/example/fuzzControll/exception/BaseException.java
View file @
0745a33d
...
@@ -15,6 +15,9 @@ public class BaseException extends RuntimeException{
...
@@ -15,6 +15,9 @@ public class BaseException extends RuntimeException{
*/
*/
private
String
module
;
private
String
module
;
public
BaseException
()
{
}
public
BaseException
(
String
defaultMessage
,
String
module
)
{
public
BaseException
(
String
defaultMessage
,
String
module
)
{
this
.
defaultMessage
=
defaultMessage
;
this
.
defaultMessage
=
defaultMessage
;
this
.
module
=
module
;
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;
...
@@ -3,8 +3,12 @@ package com.example.fuzzControll.exception;
/**
/**
* cmd运行异常
* cmd运行异常
*/
*/
public
class
CmdException
extends
BaseException
{
public
class
CmdException
extends
BaseException
{
private
static
final
long
serialVersionUID
=
1L
;
private
static
final
long
serialVersionUID
=
1L
;
public
CmdException
()
{
}
public
CmdException
(
String
defaultMessage
)
{
public
CmdException
(
String
defaultMessage
)
{
super
(
defaultMessage
,
"cmd"
);
super
(
defaultMessage
,
"cmd"
);
}
}
...
...
fuzzbackend/src/main/java/com/example/fuzzControll/service/SeedFileService.java
View file @
0745a33d
...
@@ -10,5 +10,5 @@ public interface SeedFileService {
...
@@ -10,5 +10,5 @@ public interface SeedFileService {
void
delFile
(
String
fileName
);
void
delFile
(
String
fileName
);
void
upload
(
MultipartFile
file
);
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 {
...
@@ -23,27 +23,42 @@ public class SeedFileServiceImpl implements SeedFileService {
@Override
@Override
public
List
<
String
>
getSeedFiles
()
throws
CmdException
{
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 同步修改可能会出现问题
//todo 同步修改可能会出现问题
@Override
@Override
public
void
delFile
(
String
fileName
)
throws
CmdException
{
public
void
delFile
(
String
fileName
)
throws
CmdException
{
int
fileCountBefore
=
getSeedFileCount
();
int
fileCountBefore
=
0
;
cmdTools
.
runCmd
(
CmdConstent
.
DELETE_FILE
+
properties
.
getSeedPath
()
+
"/"
+
fileName
);
int
fileCountAfter
=
0
;
int
fileCountAfter
=
getSeedFileCount
();
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
){
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
@Override
public
void
upload
(
MultipartFile
file
)
throws
FileException
{
public
void
upload
(
MultipartFile
file
)
throws
FileException
,
CmdException
{
int
fileCountBefore
=
getSeedFileCount
();
fileTools
.
load
(
file
);
int
fileCountBefore
=
0
;
int
fileCountAfter
=
getSeedFileCount
();
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
){
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 {
...
@@ -52,9 +67,14 @@ public class SeedFileServiceImpl implements SeedFileService {
* 获取种子文件目录下文件数量
* 获取种子文件目录下文件数量
*/
*/
@Override
@Override
public
int
getSeedFileCount
()
throws
CmdException
{
public
int
getSeedFileCount
(
String
msg
)
throws
CmdException
{
List
<
String
>
files
=
cmdTools
.
runCmd
(
CmdConstent
.
GET_FILE_NAME
+
properties
.
getSeedPath
());
int
count
=
0
;
int
count
=
files
.
size
();
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
;
return
count
;
}
}
}
}
fuzzbackend/src/main/java/com/example/fuzzControll/tools/CmdTools.java
View file @
0745a33d
...
@@ -24,7 +24,7 @@ public class CmdTools {
...
@@ -24,7 +24,7 @@ public class CmdTools {
/**
/**
* 运行不需要后台运行cmd
* 运行不需要后台运行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
>();
List
<
String
>
result
=
new
ArrayList
<
String
>();
try
{
try
{
Process
process
=
Runtime
.
getRuntime
().
exec
(
cmd
);
Process
process
=
Runtime
.
getRuntime
().
exec
(
cmd
);
...
@@ -32,7 +32,7 @@ public class CmdTools {
...
@@ -32,7 +32,7 @@ public class CmdTools {
printMessage
(
process
.
getErrorStream
(),
new
ArrayList
<
String
>());
printMessage
(
process
.
getErrorStream
(),
new
ArrayList
<
String
>());
process
.
waitFor
();
process
.
waitFor
();
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
throw
new
CmdException
(
"run delete or search cmd error
!"
);
throw
new
CmdException
(
caller
+
" run cmd failed
!"
);
}
}
return
result
;
return
result
;
...
...
fuzzbackend/src/main/java/com/example/fuzzControll/tools/FileTools.java
View file @
0745a33d
...
@@ -3,6 +3,7 @@ package com.example.fuzzControll.tools;
...
@@ -3,6 +3,7 @@ package com.example.fuzzControll.tools;
import
com.example.fuzzControll.conf.SpringContextUtil
;
import
com.example.fuzzControll.conf.SpringContextUtil
;
import
com.example.fuzzControll.conf.SeedProperties
;
import
com.example.fuzzControll.conf.SeedProperties
;
import
com.example.fuzzControll.exception.FileException
;
import
com.example.fuzzControll.exception.FileException
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.web.multipart.MultipartFile
;
import
org.springframework.web.multipart.MultipartFile
;
import
java.io.BufferedInputStream
;
import
java.io.BufferedInputStream
;
...
@@ -10,24 +11,25 @@ import java.io.BufferedOutputStream;
...
@@ -10,24 +11,25 @@ import java.io.BufferedOutputStream;
import
java.io.FileOutputStream
;
import
java.io.FileOutputStream
;
import
java.io.InputStream
;
import
java.io.InputStream
;
@Slf4j
public
class
FileTools
{
public
class
FileTools
{
SeedProperties
properties
=
(
SeedProperties
)
SpringContextUtil
.
getBean
(
"seedProperties"
);
SeedProperties
properties
=
(
SeedProperties
)
SpringContextUtil
.
getBean
(
"seedProperties"
);
public
void
load
(
MultipartFile
file
)
throws
FileException
{
public
void
load
(
MultipartFile
file
)
throws
FileException
{
if
(
file
==
null
)
{
if
(
file
==
null
)
{
throw
new
FileException
(
"upload file is null !"
);
throw
new
FileException
(
"upload file is null !"
);
}
}
try
(
InputStream
inputStream
=
file
.
getInputStream
();
try
(
InputStream
inputStream
=
file
.
getInputStream
();
FileOutputStream
outputStream
=
new
FileOutputStream
(
properties
.
getSeedPath
()
+
"/"
+
file
.
getOriginalFilename
());)
{
FileOutputStream
outputStream
=
new
FileOutputStream
(
properties
.
getSeedPath
()
+
"/"
+
file
.
getOriginalFilename
());)
{
BufferedInputStream
bufferedInputStream
=
new
BufferedInputStream
(
inputStream
);
BufferedInputStream
bufferedInputStream
=
new
BufferedInputStream
(
inputStream
);
BufferedOutputStream
bufferedOutputStream
=
new
BufferedOutputStream
(
outputStream
);
BufferedOutputStream
bufferedOutputStream
=
new
BufferedOutputStream
(
outputStream
);
byte
[]
buffer
=
new
byte
[
1024
];
byte
[]
buffer
=
new
byte
[
1024
];
int
bytesRead
;
int
bytesRead
;
while
((
bytesRead
=
bufferedInputStream
.
read
(
buffer
))
!=
-
1
)
{
while
((
bytesRead
=
bufferedInputStream
.
read
(
buffer
))
!=
-
1
)
{
bufferedOutputStream
.
write
(
buffer
,
0
,
bytesRead
);
bufferedOutputStream
.
write
(
buffer
,
0
,
bytesRead
);
}
}
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
new
FileException
(
"write file error !"
);
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