001/* 002 * Syncany, www.syncany.org 003 * Copyright (C) 2011-2016 Philipp C. Heckel <philipp.heckel@gmail.com> 004 * 005 * This program is free software: you can redistribute it and/or modify 006 * it under the terms of the GNU General Public License as published by 007 * the Free Software Foundation, either version 3 of the License, or 008 * (at your option) any later version. 009 * 010 * This program is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 013 * GNU General Public License for more details. 014 * 015 * You should have received a copy of the GNU General Public License 016 * along with this program. If not, see <http://www.gnu.org/licenses/>. 017 */ 018package org.syncany.operations.cleanup; 019 020import java.util.SortedMap; 021import java.util.TreeMap; 022 023import org.simpleframework.xml.Element; 024import org.simpleframework.xml.ElementMap; 025import org.syncany.operations.OperationOptions; 026import org.syncany.operations.status.StatusOperationOptions; 027 028public class CleanupOperationOptions implements OperationOptions { 029 @Element(name = "status", required = false) 030 private StatusOperationOptions statusOptions = new StatusOperationOptions(); 031 032 @Element(required = false) 033 private boolean force = false; 034 035 @Element(required = false) 036 private boolean removeOldVersions = true; 037 038 @Element(required = false) 039 private boolean removeVersionsByInterval = true; 040 041 @Element(required = false) 042 private boolean removeUnreferencedTemporaryFiles = true; 043 044 @Element(required = false) 045 private long minKeepDeletedSeconds = 30 * 24 * 60 * 60; // 30 days 046 047 @Element(required = false) 048 private int maxDatabaseFiles = 15; 049 050 @Element(required = false) 051 private long minSecondsBetweenCleanups = 3 * 60 * 60; // 3 hours 052 053 @ElementMap(entry = "fromTime", key = "truncateDateFormat", required = false, attribute = true, inline = true) 054 private SortedMap<Long, TimeUnit> purgeFileVersionSettings; 055 056 public CleanupOperationOptions() { 057 purgeFileVersionSettings = createDefaultPurgeFileVersionSettings(); 058 } 059 060 public StatusOperationOptions getStatusOptions() { 061 return statusOptions; 062 } 063 064 public void setStatusOptions(StatusOperationOptions statusOptions) { 065 this.statusOptions = statusOptions; 066 } 067 068 public boolean isRemoveOldVersions() { 069 return removeOldVersions; 070 } 071 072 public void setRemoveOldVersions(boolean removeOldVersions) { 073 this.removeOldVersions = removeOldVersions; 074 } 075 076 public boolean isRemoveVersionsByInterval() { 077 return removeVersionsByInterval; 078 } 079 080 public void setRemoveVersionsByInterval(boolean removeVersionsByInterval) { 081 this.removeVersionsByInterval = removeVersionsByInterval; 082 } 083 084 public boolean isRemoveUnreferencedTemporaryFiles() { 085 return removeUnreferencedTemporaryFiles; 086 } 087 088 public void setRemoveUnreferencedTemporaryFiles(boolean removeUnreferencedTemporaryFiles) { 089 this.removeUnreferencedTemporaryFiles = removeUnreferencedTemporaryFiles; 090 } 091 092 public void setMaxDatabaseFiles(int maxDatabaseFiles) { 093 this.maxDatabaseFiles = maxDatabaseFiles; 094 } 095 096 public int getMaxDatabaseFiles() { 097 return maxDatabaseFiles; 098 } 099 100 public void setMinSecondsBetweenCleanups(long minSecondsBetweenCleanups) { 101 this.minSecondsBetweenCleanups = minSecondsBetweenCleanups; 102 } 103 104 public long getMinSecondsBetweenCleanups() { 105 return minSecondsBetweenCleanups; 106 } 107 108 public void setMinKeepSeconds(long minKeepDeletedSeconds) { 109 this.minKeepDeletedSeconds = minKeepDeletedSeconds; 110 } 111 112 public long getMinKeepDeletedSeconds() { 113 return minKeepDeletedSeconds; 114 } 115 116 public SortedMap<Long, TimeUnit> getPurgeFileVersionSettings() { 117 return purgeFileVersionSettings; 118 } 119 120 public void setPurgeFileVersionSettings(SortedMap<Long, TimeUnit> newSettings) { 121 purgeFileVersionSettings = newSettings; 122 } 123 124 public boolean isForce() { 125 return force; 126 } 127 128 public void setForce(boolean force) { 129 this.force = force; 130 } 131 132 /** 133 * This function returns a Map which describes how to purge file versions. 134 * 135 * Each key-value pair has a long and a string, representing the following: 136 * The string determines the behavior we use up to long seconds in the past. 137 * ie. If the first pair is (3600, TimeUnit.MINUTES), we keep 1 version every minute for the last hour. 138 * If the second pair is (3*24*3600, TimeUnit.HOURS), we keep 1 version every hour for the last three days, 139 * except the last hour, for which the above policy holds. 140 */ 141 private SortedMap<Long, TimeUnit> createDefaultPurgeFileVersionSettings() { 142 TreeMap<Long, TimeUnit> purgeSettings = new TreeMap<Long, TimeUnit>(); 143 144 purgeSettings.put(30L * 24L * 3600L, TimeUnit.DAYS); 145 purgeSettings.put(3L * 24L * 3600L, TimeUnit.HOURS); 146 purgeSettings.put(3600L, TimeUnit.MINUTES); 147 148 return purgeSettings; 149 } 150 151 public enum TimeUnit { 152 YEARS, MONTHS, WEEKS, DAYS, HOURS, MINUTES, SECONDS 153 } 154}