Skip to content

Commit

Permalink
Removed /etc/network/interfaces.tmp after it has been consumed (#3872)
Browse files Browse the repository at this point in the history
* Removed /etc/network/interfaces.tmp after it has been consumed

Signed-off-by: Marcello Martina <[email protected]>

* Applied same changes to linux.redhat.provider

Signed-off-by: Marcello Martina <[email protected]>
  • Loading branch information
marcellorinaldo authored Mar 15, 2022
1 parent aff400d commit fb92f4e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
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());
}
}
}

0 comments on commit fb92f4e

Please sign in to comment.