Skip to content

Commit

Permalink
Merge pull request #131 from JakduK/develop
Browse files Browse the repository at this point in the history
핫픽스 v0.7.4
  • Loading branch information
pio authored Oct 6, 2016
2 parents 6a94cae + 07055a4 commit 3c4a10f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

/**
* 오래된 사진파일과 DB document를 삭제한다.
*
* Created by pyohwan on 16. 10. 6.
*/

Expand Down Expand Up @@ -66,7 +67,6 @@ public ItemReader<Gallery> removeOldGalleryReader() {
itemReader.setTemplate(mongoOperations);
itemReader.setTargetType(Gallery.class);
itemReader.setPageSize(100);
itemReader.setMaxItemCount(1);
itemReader.setQuery(query);

Map<String, Sort.Direction> sorts = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,42 +41,42 @@ public Gallery process(Gallery item) {
String.valueOf(timePoint.getDayOfMonth()), item.getId());

if (Files.exists(imagePath, LinkOption.NOFOLLOW_LINKS) && Files.exists(thumbPath, LinkOption.NOFOLLOW_LINKS)) {

deleteGalleryFile(imagePath);
deleteGalleryFile(thumbPath);

System.out.println("path=" + imagePath + ", gallery id=" + item.getId());

galleryRepository.delete(item);
try {
deleteGalleryFile(imagePath);
deleteGalleryFile(thumbPath);
System.out.println("path=" + imagePath + ", gallery id=" + item.getId());

galleryRepository.delete(item);
} catch (IOException e) {
e.printStackTrace();
}
} else {
System.out.println("Not exist path=" + imagePath);
}

return item;
}

private void deleteGalleryFile(Path path) {
try {
Files.deleteIfExists(path);
Path imagePathOfDay = path.getParent();
DirectoryStream<Path> imagePathOfDayDs = Files.newDirectoryStream(imagePathOfDay);
private void deleteGalleryFile(Path path) throws IOException {
Files.deleteIfExists(path);
Path imagePathOfDay = path.getParent();
DirectoryStream<Path> imagePathOfDayDs = Files.newDirectoryStream(imagePathOfDay);

if (! imagePathOfDayDs.iterator().hasNext()) {
Files.deleteIfExists(imagePathOfDay);
if (! imagePathOfDayDs.iterator().hasNext()) {
Files.deleteIfExists(imagePathOfDay);

Path imagePathOfMonth = imagePathOfDay.getParent();
DirectoryStream<Path> imagePathOfMonthDs = Files.newDirectoryStream(imagePathOfMonth);
Path imagePathOfMonth = imagePathOfDay.getParent();
DirectoryStream<Path> imagePathOfMonthDs = Files.newDirectoryStream(imagePathOfMonth);

if (! imagePathOfMonthDs.iterator().hasNext()) {
Files.deleteIfExists(imagePathOfMonth);
if (! imagePathOfMonthDs.iterator().hasNext()) {
Files.deleteIfExists(imagePathOfMonth);

Path imagePathOfYear = imagePathOfMonth.getParent();
DirectoryStream<Path> imagePathOfYearDs = Files.newDirectoryStream(imagePathOfYear);
Path imagePathOfYear = imagePathOfMonth.getParent();
DirectoryStream<Path> imagePathOfYearDs = Files.newDirectoryStream(imagePathOfYear);

if (! imagePathOfYearDs.iterator().hasNext())
Files.deleteIfExists(imagePathOfYear);
}
if (! imagePathOfYearDs.iterator().hasNext())
Files.deleteIfExists(imagePathOfYear);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}

0 comments on commit 3c4a10f

Please sign in to comment.