MCPcopy Create free account
hub / github.com/PCGen/pcgen / createBackupForFile

Method createBackupForFile

code/src/java/pcgen/io/IOHandler.java:130–150  ·  view source on GitHub ↗

Create a backup of the specified file, but only if backups are enabled, the file exists and the file is not empty. @param outFile The file to be backed up.

(File outFile)

Source from the content-addressed store, hash-verified

128 * @param outFile The file to be backed up.
129 */
130 public void createBackupForFile(File outFile)
131 {
132 // Make a backup of the old file, if it exists and isn't empty
133 if (PCGenSettings.getCreatePcgBackup() && outFile.exists() && outFile.length() > 0)
134 {
135 String file = outFile.getName();
136 String backupPcgPath = PCGenSettings.getBackupPcgDir();
137 if (backupPcgPath == null || backupPcgPath.isEmpty())
138 {
139 backupPcgPath = outFile.getParent();
140 }
141 final String BAK_PREFIX = ".bak"; //$NON-NLS-1$
142 File bakFile = new File(backupPcgPath, file + BAK_PREFIX);
143
144 if (bakFile.exists() && outFile.exists() && outFile.length() > 0)
145 {
146 bakFile.delete();
147 }
148 outFile.renameTo(bakFile);
149 }
150 }
151
152 /**
153 * Reads the contents of the given PlayerCharacter from a stream

Callers 2

writeMethod · 0.95
writeMethod · 0.80

Calls 6

getCreatePcgBackupMethod · 0.95
getBackupPcgDirMethod · 0.95
getNameMethod · 0.65
isEmptyMethod · 0.65
getParentMethod · 0.65
existsMethod · 0.45

Tested by

no test coverage detected