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

解决执行 transferFileAtom 后遗留的 lock 文件没有真正删除的问题 #305

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 @@ -205,10 +205,6 @@ public static void transferFileAtom(File src, File dest, boolean isDeleteSource)
} catch (IOException e) {
logger.warn(e.toString());
}

if (lockFile != null) {
lockFile.delete();
}
}
if (outStream != null) {
try {
Expand All @@ -217,6 +213,9 @@ public static void transferFileAtom(File src, File dest, boolean isDeleteSource)
logger.warn(e.toString());
}
}
if (lockFile != null) {
lockFile.delete();
}
}

// 进行重试
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.baidu.disconf.core.test.utils;

import java.io.File;
import java.io.IOException;

import org.apache.commons.io.FileUtils;
import org.junit.Assert;
import org.junit.Test;

import com.baidu.disconf.core.common.utils.OsUtil;

public class OsUtilTestCase {

@Test
public void makeSureDeleteLockFile() {
File baseDir = new File(System.getProperty("user.dir"));
File srcFile = new File(baseDir, "srcFile.txt");
try {
FileUtils.writeStringToFile(srcFile, "test data to transfer");
} catch (IOException ex) {
}

File destFile = new File(baseDir, "destFile.txt");
try {
OsUtil.transferFileAtom(srcFile, destFile, true);
} catch (Exception e) {
Assert.fail(e.getMessage());
}

destFile.delete();

File lockFile = new File(baseDir, destFile.getName() + ".lock");
Assert.assertFalse("Failed to delete lcok file: " + lockFile.getName(), lockFile.exists());
}

}