Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed /etc/network/interfaces.tmp after it has been consumed #3872

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -430,21 +430,23 @@ private void writeConfigFile(String tmpFileName, String dstFileName, StringBuild
}

// move tmp configuration file into its final destination
copyConfigFile(srcFile, dstFile);
copyAndDeleteTmpConfigFile(srcFile, dstFile);
}

private void copyConfigFile(File srcFile, File dstFile) throws KuraException {
private void copyAndDeleteTmpConfigFile(File tmpSrcFile, File dstFile) throws KuraException {
try {
if (!FileUtils.contentEquals(srcFile, dstFile)) {
if (!FileUtils.contentEquals(tmpSrcFile, dstFile)) {
// File.renameTo performs rather badly on Windows, if the file already exists
Files.move(Paths.get(srcFile.getAbsolutePath()), Paths.get(dstFile.getAbsolutePath()),
Files.move(Paths.get(tmpSrcFile.getAbsolutePath()), Paths.get(dstFile.getAbsolutePath()),
StandardCopyOption.REPLACE_EXISTING);
} else {
logger.info("Not rewriting network interfaces file because it is the same");
}

Files.deleteIfExists(Paths.get(tmpSrcFile.getAbsolutePath()));
} catch (IOException e) {
throw new KuraIOException(e,
"Failed to rename tmp config file " + srcFile.getName() + " to " + dstFile.getName());
"Failed to rename tmp config file " + tmpSrcFile.getName() + " to " + dstFile.getName());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,21 +236,23 @@ private void writeConfigFile(String tmpFileName, String dstFileName, StringBuild
}

// move tmp configuration file into its final destination
copyConfigFile(srcFile, dstFile);
copyAndDeleteTmpConfigFile(srcFile, dstFile);
}

private void copyConfigFile(File srcFile, File dstFile) throws KuraException {
private void copyAndDeleteTmpConfigFile(File tmpSrcFile, File dstFile) throws KuraException {
try {
if (!FileUtils.contentEquals(srcFile, dstFile)) {
if (!FileUtils.contentEquals(tmpSrcFile, dstFile)) {
// File.renameTo performs rather badly on Windows, if the file already exists
Files.move(Paths.get(srcFile.getAbsolutePath()), Paths.get(dstFile.getAbsolutePath()),
Files.move(Paths.get(tmpSrcFile.getAbsolutePath()), Paths.get(dstFile.getAbsolutePath()),
StandardCopyOption.REPLACE_EXISTING);
} else {
logger.info("Not rewriting network interfaces file because it is the same");
}

Files.deleteIfExists(Paths.get(tmpSrcFile.getAbsolutePath()));
} catch (IOException e) {
throw new KuraIOException(e,
"Failed to rename tmp config file " + srcFile.getName() + " to " + dstFile.getName());
"Failed to rename tmp config file " + tmpSrcFile.getName() + " to " + dstFile.getName());
}
}
}