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

[MyPerf4J-90] Fix SysGenProfilingFile rename fail #90 #91

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from

Conversation

JiaRG
Copy link
Contributor

@JiaRG JiaRG commented Apr 2, 2023

What is the purpose of the change

fix #90

Brief ChangeLog

fix SysGenProfilingFile rename fail

Verifying this change

Follow this checklist to help us incorporate your contribution quickly and easily:

  • Make sure there is a GITHUB_issue field for the change (usually before you start working on it). Trivial changes like typos do not require a GITHUB issue. Your pull request should address just this issue, without pulling in other changes - one PR resolves one issue.
  • Format the pull request title like [MyPerf4J-XXX] Fix NullPointerException when host is null #XXX. Each commit in the pull request should have a meaningful subject line and body.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Write necessary unit-test to verify your logic correction, more mock a little better when cross module dependency exist.
  • Run mvn clean package -Dmaven.test.skip=false to make sure unit-test pass.

fileWriter.write("#This is a file automatically generated by MyPerf4J, please do not edit!\n");
fileWriter.flush();
// 流还没释放导致
Assert.assertFalse(tmpFilePath.toFile().renameTo(testFilePath1.toFile()));
Copy link
Owner

@LinShunKang LinShunKang Apr 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

在 MacOS 里这行代码执行失败

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

你之前的代码在 MacOS 里能成功吗?

Assert.assertTrue(testFilePath2.toFile().setReadOnly());
} else {
// 第一次rename能成功,后续就失败
Assert.assertFalse(tmpFilePath.toFile().renameTo(testFilePath2.toFile()));
Copy link
Owner

@LinShunKang LinShunKang Apr 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

在 MacOS 里这行代码执行失败

final File tempFile = buildTmpProfilingFile(filePath);
final Path destPath = Files.move(tempFile.toPath(), Paths.get(filePath), REPLACE_EXISTING);
final File destFile = destPath.toFile();
// 此处不能设置只读,否则在windows环境下次move的时候会报错 AccessDeniedException
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果 destFile.setReadOnly() 之后再次 move 会报错的话,那 FileTest 的第 89 行就会抛异常

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不一样,FileTest 能跑成功,但是 agent 加载到 tomcat 里面就会报错

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

File.renameTo及File.setReadOnly的问题
2 participants