Skip to content
This repository has been archived by the owner on Apr 5, 2024. It is now read-only.

Hotfix/2.1.4 #155

Merged
merged 9 commits into from
Mar 29, 2017
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
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<groupId>ninja.eivind</groupId>
<artifactId>hots-replay-uploader</artifactId>
<version>2.1.3</version>
<version>2.1.4</version>

<prerequisites>
<maven>3.0</maven>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ public boolean isPreloaderSupported() {

@Override
public BattleLobbyTempDirectories getBattleLobbyTempDirectories() {
final File root = new File(USER_HOME, "Library");
final File remainder = new File(USER_HOME + "/Library/Caches/TemporaryItems/Blizzard/Heroes of the Storm");
final File root = new File(System.getProperty("java.io.tmpdir"));
final File remainder = new File(root + "/TemporaryItems/Blizzard/Heroes of the Storm");
return new BattleLobbyTempDirectories(
root,
remainder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class WindowsService implements PlatformService {

private static final Logger LOG = LoggerFactory.getLogger(WindowsService.class);
private Desktop desktop;
private Pattern pathPattern = Pattern.compile("[a-zA-Z]:\\\\(\\\\|(\\w+|\\.)| )+");
private Pattern pathPattern = Pattern.compile("^[a-zA-Z]:\\\\(((?![<>:\"/\\\\|?*]).)+((?<![ .])\\\\)?)*$");
private File documentsHome;
public WindowsService() {
desktop = Desktop.getDesktop();
Expand Down Expand Up @@ -101,7 +101,6 @@ public BattleLobbyTempDirectories getBattleLobbyTempDirectories() {

private File findMyDocuments() throws FileNotFoundException {
Process p = null;
String myDocuments = null;
try {
LOG.info("Querying registry for Documents folder location.");
p = Runtime.getRuntime().exec("reg query \"HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders\" /v personal");
Expand All @@ -114,8 +113,7 @@ private File findMyDocuments() throws FileNotFoundException {
for (final String value : values) {
Optional<String> matchForPath = getMatchForPath(value);
if(matchForPath.isPresent()) {
myDocuments = matchForPath.get();
break;
return new File(matchForPath.get());
}
}
}
Expand All @@ -128,12 +126,10 @@ private File findMyDocuments() throws FileNotFoundException {
}
}

if (myDocuments == null) {
LOG.warn("Could not reliably query register for My Documents folder. This usually means you have" +
" a unicode name and standard location. Falling back to legacy selection:");
myDocuments = USER_HOME + "\\Documents";
LOG.warn("Result: " + myDocuments);
}
LOG.warn("Could not reliably query register for My Documents folder. This usually means you have" +
" a unicode name and standard location. Falling back to legacy selection:");
final String myDocuments = USER_HOME + "\\Documents";
LOG.warn("Result: " + myDocuments);
return new File(myDocuments);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,17 @@
public class RecursiveTempWatcherTest {

private static final Logger logger = LoggerFactory.getLogger(RecursiveTempWatcherTest.class);
@Rule
public JavaFXThreadingRule rule = new JavaFXThreadingRule();
@Autowired
private PlatformService platformService;
private RecursiveTempWatcher tempWatcher;
private BattleLobbyTempDirectories directories;

@Rule
public JavaFXThreadingRule rule = new JavaFXThreadingRule();

@Before
public void setUp() throws Exception {
directories = platformService.getBattleLobbyTempDirectories();
if(!(directories.getRoot().exists() || directories.getRoot().mkdirs())) {
if (!(directories.getRoot().exists() || directories.getRoot().mkdirs())) {
fail("Could not create tmp root");
}

Expand All @@ -69,7 +68,7 @@ public void run() {
latch.countDown();
}
});
if(!latch.await(1, TimeUnit.SECONDS)) {
if (!latch.await(1, TimeUnit.SECONDS)) {
fail("Service did not start.");
}
// give watchers some time to wind up
Expand All @@ -85,14 +84,14 @@ public void testSetCallbackIsAppliedProperly() throws Exception {

callback.accept(null);

if(!latch.await(500, TimeUnit.MILLISECONDS)) {
if (!latch.await(500, TimeUnit.MILLISECONDS)) {
throw new TimeoutException("Latch was not tripped.");
}
}

@Test
public void testCallbackIsInvokedWhenRelevantFileIsDiscovered() throws Exception {
CountDownLatch latch = new CountDownLatch(1);
final CountDownLatch latch = new CountDownLatch(1);
final File[] fileAccessor = new File[1];
final File tempWriteReplayFolder = new File(directories.getRemainder(), "TempWriteReplayP99");
final File target = new File(tempWriteReplayFolder, BattleLobbyWatcher.REPLAY_SERVER_BATTLELOBBY);
Expand All @@ -101,12 +100,16 @@ public void testCallbackIsInvokedWhenRelevantFileIsDiscovered() throws Exception
latch.countDown();
});

if(!(tempWriteReplayFolder.mkdirs() && target.createNewFile())) {
if (!(tempWriteReplayFolder.mkdirs() && target.createNewFile())) {
fail("Could not create file to drop target " + target + " in");
}

if(!latch.await(50000, TimeUnit.MILLISECONDS)) {
fail("Latch was not tripped.");
long stopAt = System.currentTimeMillis() + 50_000;
while (latch.getCount() != 0) {
if (System.currentTimeMillis() > stopAt) {
fail("Latch was not tripped");
}
Thread.sleep(1_000);
}

final String expected = target.getName();
Expand All @@ -118,7 +121,7 @@ public void testCallbackIsInvokedWhenRelevantFileIsDiscovered() throws Exception
private TempWatcher getChildRecursively(RecursiveTempWatcher tempWatcher) {
TempWatcher child = tempWatcher.getChild();
//noinspection InstanceofConcreteClass
if(child instanceof RecursiveTempWatcher) {
if (child instanceof RecursiveTempWatcher) {
return getChildRecursively((RecursiveTempWatcher) child);
}
return tempWatcher;
Expand All @@ -127,7 +130,7 @@ private TempWatcher getChildRecursively(RecursiveTempWatcher tempWatcher) {
@Test
public void testGetChildCount() throws Exception {
final File remainder = directories.getRemainder();
if(!remainder.mkdirs()) {
if (!remainder.mkdirs()) {
fail("Failed to create files.");
}

Expand All @@ -151,11 +154,11 @@ public void testGetChildCount() throws Exception {
public void tearDown() throws Exception {
CountDownLatch latch = new CountDownLatch(1);
Platform.runLater(() -> {
if(tempWatcher.cancel()) {
if (tempWatcher.cancel()) {
latch.countDown();
}
});
if(!latch.await(1, TimeUnit.SECONDS)) {
if (!latch.await(1, TimeUnit.SECONDS)) {
fail("Service failed to stop");
}
// give watchers some time to wind down recursively
Expand All @@ -168,7 +171,7 @@ private void cleanupRecursive(File file) throws InterruptedException {
for (File child : children != null ? children : new File[0]) {
cleanupRecursive(child);
}
if(file.exists() && !file.delete()) {
if (file.exists() && !file.delete()) {
fail("Failed to clean up file " + file);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,33 +33,48 @@ public void setUp() throws Exception {
@Test
public void testDocumentsPathCanContainDots() {
final String expected = "Z:\\Users\\S.omeUser\\Documents\\";
final Optional<String> matchForPath = windowsService.getMatchForPath(expected);

assertTrue("Path matches.", matchForPath.isPresent());

final String actual = matchForPath.get();
assertEquals("Path match is equal to inserted path.", expected, actual);
assertPathMatchForExpected(expected);
}

@Test
public void testGetMatchForPath() {
final String expected = "Z:\\Users\\SomeUser\\Documents\\";
final Optional<String> matchForPath = windowsService.getMatchForPath(expected);
assertPathMatchForExpected(expected);
}

assertTrue("Path matches.", matchForPath.isPresent());
@Test
public void testDocumentsPathCanContainDashes() {
final String expected = "Z:\\Users\\user-name\\Documents\\";
assertPathMatchForExpected(expected);
}

final String actual = matchForPath.get();
assertEquals("Path match is equal to inserted path.", expected, actual);
@Test
public void testDocumentsPathCanNestQuiteDeep() {
final String expected = "Z:\\Users\\username\\Documents\\OneDrive\\username\\Documents\\";
assertPathMatchForExpected(expected);
}

@Test
public void testGetMatchForPathDoesNotAllowNonCompliantUnicode() {
final String expected = "C:\\Users\\Eivind Vegsundv�g\\Documents\\";
final Optional<String> matchForPath = windowsService.getMatchForPath(expected);
public void testDocumentsPathCanContainNumbers() {
final String expected = "Z:\\Users\\user1\\Documents\\";
assertPathMatchForExpected(expected);
}

assertFalse("Path matches.", matchForPath.isPresent());
@Test
public void testCaseForIssue148() {
final String expected = "C:\\Users\\User\\OneDrive\\User-i5\\Documents";
assertPathMatchForExpected(expected);
}

private void assertPathMatchForExpected(String expected) {
final Optional<String> matchForPath = windowsService.getMatchForPath(expected);

assertTrue("Path matches.", matchForPath.isPresent());

final String actual = matchForPath.get();
assertEquals("Path match is equal to inserted path.", expected, actual);
}

@Test
public void testGetMatchForPathDoesNotMatchNonPaths() {
final String expected = "N:ot\\A\\Path\\";
Expand Down