-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
(fix) Impl moving file atomically on windows, #54 #104
Conversation
Files.deleteIfExists(tmpPath); | ||
} catch (IOException e2) { | ||
e2.addSuppressed(e1); | ||
LOG.warn("Unable to delete {}, good bye then!", tmpPath); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这行日志不错: good bye then!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已经到 good bye 地步了的话,日志 level 是不是应该为 error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
没有必要,上层会 catch 打印
} | ||
|
||
if (destFile.exists()) { | ||
LOG.info("The target file { } was already existing", destPath); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
大括号多了一个空格,另外日志是一句话,应该有一个句号
Path destPath = destFile.toPath(); | ||
try { | ||
return Files.move(tmpPath, destPath, StandardCopyOption.ATOMIC_MOVE) == destPath; | ||
} catch (IOException e) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
final IOException e
按照 jraft 的统一代码风格,应该有个 final 修饰
@@ -96,6 +105,7 @@ private void readBytes(byte[] bs, InputStream input) throws IOException { | |||
* @return true if save success |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这些东西应该工具来保证,如果工具无法做到,我觉的这个规范可以不要了。 javadoc 会处理。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
格式化插件无法做到
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
恩,那这个规范就不要了,没有必要去手工调整。参数合理说明即可。生成的 javadoc 会格式化的。
File destFile = new File(this.path); | ||
Path destPath = destFile.toPath(); | ||
try { | ||
return Files.move(tmpPath, destPath, StandardCopyOption.ATOMIC_MOVE) == destPath; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Files.move() == destPath 是个恒等式,还不如新起一行 return true 清晰
Motivation:
Use
Files.move(source,path,opts)
to replaceFile#renameTo(file)
for moving files atomically.The code is from
https://github.com/jenkinsci/jenkins/blob/master/core/src/main/java/hudson/util/AtomicFileWriter.java#L187
Modification:
Modify the
ProtoBufFile#save()
implementation.Result:
Fixes #54