|
|
@@ -9,22 +9,16 @@ import com.moekr.moocoder.util.MavenUtil;
|
|
|
import com.moekr.moocoder.util.ToolKit;
|
|
|
import com.moekr.moocoder.util.enums.Granularity;
|
|
|
import com.moekr.moocoder.web.dto.CodeDTO;
|
|
|
-import org.apache.tomcat.util.http.fileupload.FileUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import java.io.File;
|
|
|
-import java.io.FileInputStream;
|
|
|
-import java.io.FileOutputStream;
|
|
|
import java.io.IOException;
|
|
|
import java.util.Base64;
|
|
|
import java.util.Map;
|
|
|
-import java.util.zip.ZipEntry;
|
|
|
-import java.util.zip.ZipInputStream;
|
|
|
|
|
|
import static com.moekr.moocoder.logic.service.impl.ProjectPath.getProjectFullPath;
|
|
|
-import static com.moekr.moocoder.logic.service.impl.ProjectPath.tempZipDir;
|
|
|
|
|
|
/**
|
|
|
* @author miaomuzhi
|
|
|
@@ -114,54 +108,7 @@ public class ProjectServiceImpl implements ProjectService {
|
|
|
}
|
|
|
|
|
|
private boolean addClassesProject(String project, MultipartFile projectFile) {
|
|
|
- try {
|
|
|
- String projectPath = getProjectFullPath(project);
|
|
|
- File root = new File(projectPath);
|
|
|
-
|
|
|
- if (root.exists()){
|
|
|
- FileUtils.cleanDirectory(root);
|
|
|
- } else{
|
|
|
- root.mkdirs();
|
|
|
- }
|
|
|
-
|
|
|
- File temp = new File(tempZipDir + File.separator + projectFile.getOriginalFilename());
|
|
|
- projectFile.transferTo(temp);
|
|
|
-
|
|
|
- byte[] buffer = new byte[1024];
|
|
|
- try (FileInputStream fis = new FileInputStream(temp)) {
|
|
|
- try (ZipInputStream zis = new ZipInputStream(fis)) {
|
|
|
- ZipEntry zipEntry;
|
|
|
- while ((zipEntry = zis.getNextEntry()) != null) {
|
|
|
- File newFile = newFile(root, zipEntry);
|
|
|
- if (zipEntry.isDirectory() && !newFile.exists()){
|
|
|
- newFile.mkdirs();
|
|
|
- } else if (! zipEntry.isDirectory()) {
|
|
|
- try (FileOutputStream fos = new FileOutputStream(newFile)){
|
|
|
- int len;
|
|
|
- while ((len = zis.read(buffer)) > 0) {
|
|
|
- fos.write(buffer, 0, len);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- zis.closeEntry();
|
|
|
- }
|
|
|
- }
|
|
|
- return true;
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
- return false;
|
|
|
- }
|
|
|
+ throw new UnsupportedOperationException("ProjectService.addProject is not supported!");
|
|
|
}
|
|
|
|
|
|
- private File newFile(File destinationDir, ZipEntry zipEntry) throws IOException {
|
|
|
- File destFile = new File(destinationDir, zipEntry.getName());
|
|
|
- String destDirPath = destinationDir.getCanonicalPath();
|
|
|
- String destFilePath = destFile.getCanonicalPath();
|
|
|
-
|
|
|
- if (!destFilePath.startsWith(destDirPath + File.separator)) {
|
|
|
- throw new IOException("Entry is outside of the target dir: " + zipEntry.getName());
|
|
|
- }
|
|
|
- return destFile;
|
|
|
- }
|
|
|
}
|