Skip to content
This repository has been archived by the owner on Jul 7, 2020. It is now read-only.

At pull prevent silent listener override #4

Open
wants to merge 4 commits 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
8 changes: 6 additions & 2 deletions src/main/java/com/addthis/meshy/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,12 @@ public static void main(String args[]) throws Exception {
try (Meshy more = new MeshyClient(args[1], Integer.parseInt(args[2]))) {
if (args.length > 3) {
String cmd = args[3];
if (cmd.equals("ls") && args.length > 4) {
FileSource fileSource = new FileSource(more, new String[]{args[4]});
if (cmd.equals("ls")) {
String expr = args.length > 4 ? args[4] : "/*";
if (expr.endsWith("/")) {
expr += "*";
}
FileSource fileSource = new FileSource(more, new String[]{expr});
fileSource.waitComplete();
for (FileReference file : fileSource.getFileList()) {
System.out.println(file.getHostUUID() + " " + file.name + " \t " + file.size + " \t " + new Date(file.lastModified));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ public void setListener(String fileName, MessageListener listener) {
return;
}
synchronized (listeners) {
listeners.put(fileName, listener);
if (listeners.put(fileName, listener) != null) {
log.error("preventing override of file listener for {}", fileName);
return;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't actually entirely prevent the override. It will still put the new listener into the local map.

OutputStream out = source.sendMessage(MessageFileSystem.MFS_ADD);
try {
Bytes.writeString(fileName, out);
Expand All @@ -57,14 +60,17 @@ public void setListener(String fileName, MessageListener listener) {

public void deleteListener(String fileName) {
synchronized (listeners) {
if (listeners.remove(fileName) == null) {
log.error("attempting to remove absent listener for {}", fileName);
return;
}
OutputStream out = source.sendMessage(MessageFileSystem.MFS_DEL);
try {
Bytes.writeString(fileName, out);
out.close();
} catch (Exception ex) {
throw new RuntimeException(ex);
}
listeners.remove(fileName);
}
}

Expand Down