log the file name when exceptions are thrown during i/o
This commit is contained in:
parent
c7305f6b06
commit
71bfdd9bfd
@ -63,15 +63,6 @@ import java.util.stream.Collectors;
|
|||||||
public abstract class FlatfileBacking extends AbstractBacking {
|
public abstract class FlatfileBacking extends AbstractBacking {
|
||||||
private static final String LOG_FORMAT = "%s(%s): [%s] %s(%s) --> %s";
|
private static final String LOG_FORMAT = "%s(%s): [%s] %s(%s) --> %s";
|
||||||
|
|
||||||
protected static <T> T call(Callable<T> c, T def) {
|
|
||||||
try {
|
|
||||||
return c.call();
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
return def;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private final Logger actionLogger = Logger.getLogger("lp_actions");
|
private final Logger actionLogger = Logger.getLogger("lp_actions");
|
||||||
private Map<String, String> uuidCache = new ConcurrentHashMap<>();
|
private Map<String, String> uuidCache = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
@ -216,6 +207,16 @@ public abstract class FlatfileBacking extends AbstractBacking {
|
|||||||
plugin.applyToFileWatcher(fileWatcher -> fileWatcher.registerChange(type, file.getName()));
|
plugin.applyToFileWatcher(fileWatcher -> fileWatcher.registerChange(type, file.getName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected <T> T call(String file, Callable<T> c, T def) {
|
||||||
|
try {
|
||||||
|
return c.call();
|
||||||
|
} catch (Exception e) {
|
||||||
|
plugin.getLog().warn("Exception thrown whilst performing i/o: " + file);
|
||||||
|
e.printStackTrace();
|
||||||
|
return def;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean logAction(LogEntry entry) {
|
public boolean logAction(LogEntry entry) {
|
||||||
actionLogger.info(String.format(LOG_FORMAT,
|
actionLogger.info(String.format(LOG_FORMAT,
|
||||||
@ -266,7 +267,7 @@ public abstract class FlatfileBacking extends AbstractBacking {
|
|||||||
public boolean deleteGroup(Group group) {
|
public boolean deleteGroup(Group group) {
|
||||||
group.getIoLock().lock();
|
group.getIoLock().lock();
|
||||||
try {
|
try {
|
||||||
return call(() -> {
|
return call(group.getName(), () -> {
|
||||||
File groupFile = new File(groupsDir, group.getName() + fileExtension);
|
File groupFile = new File(groupsDir, group.getName() + fileExtension);
|
||||||
registerFileAction("groups", groupFile);
|
registerFileAction("groups", groupFile);
|
||||||
|
|
||||||
@ -301,7 +302,7 @@ public abstract class FlatfileBacking extends AbstractBacking {
|
|||||||
public boolean deleteTrack(Track track) {
|
public boolean deleteTrack(Track track) {
|
||||||
track.getIoLock().lock();
|
track.getIoLock().lock();
|
||||||
try {
|
try {
|
||||||
return call(() -> {
|
return call(track.getName(), () -> {
|
||||||
File trackFile = new File(tracksDir, track.getName() + fileExtension);
|
File trackFile = new File(tracksDir, track.getName() + fileExtension);
|
||||||
registerFileAction("tracks", trackFile);
|
registerFileAction("tracks", trackFile);
|
||||||
|
|
||||||
|
@ -94,28 +94,31 @@ public class JSONBacking extends FlatfileBacking {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean applyBulkUpdate(BulkUpdate bulkUpdate) {
|
public boolean applyBulkUpdate(BulkUpdate bulkUpdate) {
|
||||||
return call(() -> {
|
return call("null", () -> {
|
||||||
if (bulkUpdate.getDataType().isIncludingUsers()) {
|
if (bulkUpdate.getDataType().isIncludingUsers()) {
|
||||||
File[] files = usersDir.listFiles((dir, name1) -> name1.endsWith(".json"));
|
File[] files = usersDir.listFiles((dir, name1) -> name1.endsWith(".json"));
|
||||||
if (files == null) return false;
|
if (files == null) return false;
|
||||||
|
|
||||||
for (File file : files) {
|
for (File file : files) {
|
||||||
registerFileAction("users", file);
|
call(file.getName(), () -> {
|
||||||
|
registerFileAction("users", file);
|
||||||
|
|
||||||
JsonObject object = readObjectFromFile(file);
|
JsonObject object = readObjectFromFile(file);
|
||||||
|
|
||||||
Set<NodeModel> nodes = new HashSet<>();
|
Set<NodeModel> nodes = new HashSet<>();
|
||||||
nodes.addAll(deserializePermissions(object.get("permissions").getAsJsonArray()));
|
nodes.addAll(deserializePermissions(object.get("permissions").getAsJsonArray()));
|
||||||
|
|
||||||
Set<NodeModel> results = nodes.stream()
|
Set<NodeModel> results = nodes.stream()
|
||||||
.map(n -> Optional.ofNullable(bulkUpdate.apply(n)))
|
.map(n -> Optional.ofNullable(bulkUpdate.apply(n)))
|
||||||
.filter(Optional::isPresent)
|
.filter(Optional::isPresent)
|
||||||
.map(Optional::get)
|
.map(Optional::get)
|
||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
|
|
||||||
object.add("permissions", serializePermissions(results));
|
object.add("permissions", serializePermissions(results));
|
||||||
|
|
||||||
writeElementToFile(file, object);
|
writeElementToFile(file, object);
|
||||||
|
return true;
|
||||||
|
}, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,22 +127,25 @@ public class JSONBacking extends FlatfileBacking {
|
|||||||
if (files == null) return false;
|
if (files == null) return false;
|
||||||
|
|
||||||
for (File file : files) {
|
for (File file : files) {
|
||||||
registerFileAction("groups", file);
|
call(file.getName(), () -> {
|
||||||
|
registerFileAction("groups", file);
|
||||||
|
|
||||||
JsonObject object = readObjectFromFile(file);
|
JsonObject object = readObjectFromFile(file);
|
||||||
|
|
||||||
Set<NodeModel> nodes = new HashSet<>();
|
Set<NodeModel> nodes = new HashSet<>();
|
||||||
nodes.addAll(deserializePermissions(object.get("permissions").getAsJsonArray()));
|
nodes.addAll(deserializePermissions(object.get("permissions").getAsJsonArray()));
|
||||||
|
|
||||||
Set<NodeModel> results = nodes.stream()
|
Set<NodeModel> results = nodes.stream()
|
||||||
.map(n -> Optional.ofNullable(bulkUpdate.apply(n)))
|
.map(n -> Optional.ofNullable(bulkUpdate.apply(n)))
|
||||||
.filter(Optional::isPresent)
|
.filter(Optional::isPresent)
|
||||||
.map(Optional::get)
|
.map(Optional::get)
|
||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
|
|
||||||
object.add("permissions", serializePermissions(results));
|
object.add("permissions", serializePermissions(results));
|
||||||
|
|
||||||
writeElementToFile(file, object);
|
writeElementToFile(file, object);
|
||||||
|
return true;
|
||||||
|
}, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -152,7 +158,7 @@ public class JSONBacking extends FlatfileBacking {
|
|||||||
User user = plugin.getUserManager().getOrMake(UserIdentifier.of(uuid, username));
|
User user = plugin.getUserManager().getOrMake(UserIdentifier.of(uuid, username));
|
||||||
user.getIoLock().lock();
|
user.getIoLock().lock();
|
||||||
try {
|
try {
|
||||||
return call(() -> {
|
return call(uuid.toString(), () -> {
|
||||||
File userFile = new File(usersDir, uuid.toString() + ".json");
|
File userFile = new File(usersDir, uuid.toString() + ".json");
|
||||||
registerFileAction("users", userFile);
|
registerFileAction("users", userFile);
|
||||||
|
|
||||||
@ -199,7 +205,7 @@ public class JSONBacking extends FlatfileBacking {
|
|||||||
public boolean saveUser(User user) {
|
public boolean saveUser(User user) {
|
||||||
user.getIoLock().lock();
|
user.getIoLock().lock();
|
||||||
try {
|
try {
|
||||||
return call(() -> {
|
return call(user.getUuid().toString(), () -> {
|
||||||
File userFile = new File(usersDir, user.getUuid().toString() + ".json");
|
File userFile = new File(usersDir, user.getUuid().toString() + ".json");
|
||||||
registerFileAction("users", userFile);
|
registerFileAction("users", userFile);
|
||||||
|
|
||||||
@ -236,29 +242,32 @@ public class JSONBacking extends FlatfileBacking {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean cleanupUsers() {
|
public boolean cleanupUsers() {
|
||||||
return call(() -> {
|
return call("null", () -> {
|
||||||
File[] files = usersDir.listFiles((dir, name1) -> name1.endsWith(".json"));
|
File[] files = usersDir.listFiles((dir, name1) -> name1.endsWith(".json"));
|
||||||
if (files == null) return false;
|
if (files == null) return false;
|
||||||
|
|
||||||
for (File file : files) {
|
for (File file : files) {
|
||||||
registerFileAction("users", file);
|
call(file.getName(), () -> {
|
||||||
|
registerFileAction("users", file);
|
||||||
|
|
||||||
JsonObject object = readObjectFromFile(file);
|
JsonObject object = readObjectFromFile(file);
|
||||||
|
|
||||||
Set<NodeModel> nodes = new HashSet<>();
|
Set<NodeModel> nodes = new HashSet<>();
|
||||||
nodes.addAll(deserializePermissions(object.get("permissions").getAsJsonArray()));
|
nodes.addAll(deserializePermissions(object.get("permissions").getAsJsonArray()));
|
||||||
|
|
||||||
boolean shouldDelete = false;
|
boolean shouldDelete = false;
|
||||||
if (nodes.size() == 1) {
|
if (nodes.size() == 1) {
|
||||||
for (NodeModel e : nodes) {
|
for (NodeModel e : nodes) {
|
||||||
// There's only one
|
// There's only one
|
||||||
shouldDelete = e.getPermission().equalsIgnoreCase("group.default") && e.isValue();
|
shouldDelete = e.getPermission().equalsIgnoreCase("group.default") && e.isValue();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (shouldDelete) {
|
if (shouldDelete) {
|
||||||
file.delete();
|
file.delete();
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
|
}, true);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}, false);
|
}, false);
|
||||||
@ -267,27 +276,30 @@ public class JSONBacking extends FlatfileBacking {
|
|||||||
@Override
|
@Override
|
||||||
public List<HeldPermission<UUID>> getUsersWithPermission(String permission) {
|
public List<HeldPermission<UUID>> getUsersWithPermission(String permission) {
|
||||||
ImmutableList.Builder<HeldPermission<UUID>> held = ImmutableList.builder();
|
ImmutableList.Builder<HeldPermission<UUID>> held = ImmutableList.builder();
|
||||||
boolean success = call(() -> {
|
boolean success = call("null", () -> {
|
||||||
File[] files = usersDir.listFiles((dir, name1) -> name1.endsWith(".json"));
|
File[] files = usersDir.listFiles((dir, name1) -> name1.endsWith(".json"));
|
||||||
if (files == null) return false;
|
if (files == null) return false;
|
||||||
|
|
||||||
for (File file : files) {
|
for (File file : files) {
|
||||||
registerFileAction("users", file);
|
call(file.getName(), () -> {
|
||||||
|
registerFileAction("users", file);
|
||||||
|
|
||||||
UUID holder = UUID.fromString(file.getName().substring(0, file.getName().length() - 5));
|
UUID holder = UUID.fromString(file.getName().substring(0, file.getName().length() - 5));
|
||||||
|
|
||||||
JsonObject object = readObjectFromFile(file);
|
JsonObject object = readObjectFromFile(file);
|
||||||
|
|
||||||
Set<NodeModel> nodes = new HashSet<>();
|
Set<NodeModel> nodes = new HashSet<>();
|
||||||
nodes.addAll(deserializePermissions(object.get("permissions").getAsJsonArray()));
|
nodes.addAll(deserializePermissions(object.get("permissions").getAsJsonArray()));
|
||||||
|
|
||||||
for (NodeModel e : nodes) {
|
for (NodeModel e : nodes) {
|
||||||
if (!e.getPermission().equalsIgnoreCase(permission)) {
|
if (!e.getPermission().equalsIgnoreCase(permission)) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
held.add(NodeHeldPermission.of(holder, e));
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
held.add(NodeHeldPermission.of(holder, e));
|
}, true);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}, false);
|
}, false);
|
||||||
@ -299,7 +311,7 @@ public class JSONBacking extends FlatfileBacking {
|
|||||||
Group group = plugin.getGroupManager().getOrMake(name);
|
Group group = plugin.getGroupManager().getOrMake(name);
|
||||||
group.getIoLock().lock();
|
group.getIoLock().lock();
|
||||||
try {
|
try {
|
||||||
return call(() -> {
|
return call(name, () -> {
|
||||||
File groupFile = new File(groupsDir, name + ".json");
|
File groupFile = new File(groupsDir, name + ".json");
|
||||||
registerFileAction("groups", groupFile);
|
registerFileAction("groups", groupFile);
|
||||||
|
|
||||||
@ -336,7 +348,7 @@ public class JSONBacking extends FlatfileBacking {
|
|||||||
Group group = plugin.getGroupManager().getOrMake(name);
|
Group group = plugin.getGroupManager().getOrMake(name);
|
||||||
group.getIoLock().lock();
|
group.getIoLock().lock();
|
||||||
try {
|
try {
|
||||||
return call(() -> {
|
return call(name, () -> {
|
||||||
File groupFile = new File(groupsDir, name + ".json");
|
File groupFile = new File(groupsDir, name + ".json");
|
||||||
registerFileAction("groups", groupFile);
|
registerFileAction("groups", groupFile);
|
||||||
|
|
||||||
@ -359,7 +371,7 @@ public class JSONBacking extends FlatfileBacking {
|
|||||||
public boolean saveGroup(Group group) {
|
public boolean saveGroup(Group group) {
|
||||||
group.getIoLock().lock();
|
group.getIoLock().lock();
|
||||||
try {
|
try {
|
||||||
return call(() -> {
|
return call(group.getName(), () -> {
|
||||||
File groupFile = new File(groupsDir, group.getName() + ".json");
|
File groupFile = new File(groupsDir, group.getName() + ".json");
|
||||||
registerFileAction("groups", groupFile);
|
registerFileAction("groups", groupFile);
|
||||||
|
|
||||||
@ -386,27 +398,30 @@ public class JSONBacking extends FlatfileBacking {
|
|||||||
@Override
|
@Override
|
||||||
public List<HeldPermission<String>> getGroupsWithPermission(String permission) {
|
public List<HeldPermission<String>> getGroupsWithPermission(String permission) {
|
||||||
ImmutableList.Builder<HeldPermission<String>> held = ImmutableList.builder();
|
ImmutableList.Builder<HeldPermission<String>> held = ImmutableList.builder();
|
||||||
boolean success = call(() -> {
|
boolean success = call("null", () -> {
|
||||||
File[] files = groupsDir.listFiles((dir, name1) -> name1.endsWith(".json"));
|
File[] files = groupsDir.listFiles((dir, name1) -> name1.endsWith(".json"));
|
||||||
if (files == null) return false;
|
if (files == null) return false;
|
||||||
|
|
||||||
for (File file : files) {
|
for (File file : files) {
|
||||||
registerFileAction("groups", file);
|
call(file.getName(), () -> {
|
||||||
|
registerFileAction("groups", file);
|
||||||
|
|
||||||
String holder = file.getName().substring(0, file.getName().length() - 5);
|
String holder = file.getName().substring(0, file.getName().length() - 5);
|
||||||
|
|
||||||
JsonObject object = readObjectFromFile(file);
|
JsonObject object = readObjectFromFile(file);
|
||||||
|
|
||||||
Set<NodeModel> nodes = new HashSet<>();
|
Set<NodeModel> nodes = new HashSet<>();
|
||||||
nodes.addAll(deserializePermissions(object.get("permissions").getAsJsonArray()));
|
nodes.addAll(deserializePermissions(object.get("permissions").getAsJsonArray()));
|
||||||
|
|
||||||
for (NodeModel e : nodes) {
|
for (NodeModel e : nodes) {
|
||||||
if (!e.getPermission().equalsIgnoreCase(permission)) {
|
if (!e.getPermission().equalsIgnoreCase(permission)) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
held.add(NodeHeldPermission.of(holder, e));
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
held.add(NodeHeldPermission.of(holder, e));
|
}, true);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}, false);
|
}, false);
|
||||||
@ -418,7 +433,7 @@ public class JSONBacking extends FlatfileBacking {
|
|||||||
Track track = plugin.getTrackManager().getOrMake(name);
|
Track track = plugin.getTrackManager().getOrMake(name);
|
||||||
track.getIoLock().lock();
|
track.getIoLock().lock();
|
||||||
try {
|
try {
|
||||||
return call(() -> {
|
return call(name, () -> {
|
||||||
File trackFile = new File(tracksDir, name + ".json");
|
File trackFile = new File(tracksDir, name + ".json");
|
||||||
registerFileAction("tracks", trackFile);
|
registerFileAction("tracks", trackFile);
|
||||||
|
|
||||||
@ -459,7 +474,7 @@ public class JSONBacking extends FlatfileBacking {
|
|||||||
Track track = plugin.getTrackManager().getOrMake(name);
|
Track track = plugin.getTrackManager().getOrMake(name);
|
||||||
track.getIoLock().lock();
|
track.getIoLock().lock();
|
||||||
try {
|
try {
|
||||||
return call(() -> {
|
return call(name, () -> {
|
||||||
File trackFile = new File(tracksDir, name + ".json");
|
File trackFile = new File(tracksDir, name + ".json");
|
||||||
registerFileAction("tracks", trackFile);
|
registerFileAction("tracks", trackFile);
|
||||||
|
|
||||||
@ -485,7 +500,7 @@ public class JSONBacking extends FlatfileBacking {
|
|||||||
public boolean saveTrack(Track track) {
|
public boolean saveTrack(Track track) {
|
||||||
track.getIoLock().lock();
|
track.getIoLock().lock();
|
||||||
try {
|
try {
|
||||||
return call(() -> {
|
return call(track.getName(), () -> {
|
||||||
File trackFile = new File(tracksDir, track.getName() + ".json");
|
File trackFile = new File(tracksDir, track.getName() + ".json");
|
||||||
registerFileAction("tracks", trackFile);
|
registerFileAction("tracks", trackFile);
|
||||||
|
|
||||||
|
@ -98,27 +98,30 @@ public class YAMLBacking extends FlatfileBacking {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean applyBulkUpdate(BulkUpdate bulkUpdate) {
|
public boolean applyBulkUpdate(BulkUpdate bulkUpdate) {
|
||||||
return call(() -> {
|
return call("null", () -> {
|
||||||
if (bulkUpdate.getDataType().isIncludingUsers()) {
|
if (bulkUpdate.getDataType().isIncludingUsers()) {
|
||||||
File[] files = usersDir.listFiles((dir, name1) -> name1.endsWith(".yml"));
|
File[] files = usersDir.listFiles((dir, name1) -> name1.endsWith(".yml"));
|
||||||
if (files == null) return false;
|
if (files == null) return false;
|
||||||
|
|
||||||
for (File file : files) {
|
for (File file : files) {
|
||||||
registerFileAction("users", file);
|
call(file.getName(), () -> {
|
||||||
|
registerFileAction("users", file);
|
||||||
|
|
||||||
Map<String, Object> values = readMapFromFile(file);
|
Map<String, Object> values = readMapFromFile(file);
|
||||||
|
|
||||||
Set<NodeModel> nodes = new HashSet<>();
|
Set<NodeModel> nodes = new HashSet<>();
|
||||||
nodes.addAll(deserializePermissions((List<Object>) values.get("permissions")));
|
nodes.addAll(deserializePermissions((List<Object>) values.get("permissions")));
|
||||||
|
|
||||||
Set<NodeModel> results = nodes.stream()
|
Set<NodeModel> results = nodes.stream()
|
||||||
.map(n -> Optional.ofNullable(bulkUpdate.apply(n)))
|
.map(n -> Optional.ofNullable(bulkUpdate.apply(n)))
|
||||||
.filter(Optional::isPresent)
|
.filter(Optional::isPresent)
|
||||||
.map(Optional::get)
|
.map(Optional::get)
|
||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
|
|
||||||
values.put("permissions", serializePermissions(results));
|
values.put("permissions", serializePermissions(results));
|
||||||
writeMapToFile(file, values);
|
writeMapToFile(file, values);
|
||||||
|
return true;
|
||||||
|
}, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,21 +130,24 @@ public class YAMLBacking extends FlatfileBacking {
|
|||||||
if (files == null) return false;
|
if (files == null) return false;
|
||||||
|
|
||||||
for (File file : files) {
|
for (File file : files) {
|
||||||
registerFileAction("groups", file);
|
call(file.getName(), () -> {
|
||||||
|
registerFileAction("groups", file);
|
||||||
|
|
||||||
Map<String, Object> values = readMapFromFile(file);
|
Map<String, Object> values = readMapFromFile(file);
|
||||||
|
|
||||||
Set<NodeModel> nodes = new HashSet<>();
|
Set<NodeModel> nodes = new HashSet<>();
|
||||||
nodes.addAll(deserializePermissions((List<Object>) values.get("permissions")));
|
nodes.addAll(deserializePermissions((List<Object>) values.get("permissions")));
|
||||||
|
|
||||||
Set<NodeModel> results = nodes.stream()
|
Set<NodeModel> results = nodes.stream()
|
||||||
.map(n -> Optional.ofNullable(bulkUpdate.apply(n)))
|
.map(n -> Optional.ofNullable(bulkUpdate.apply(n)))
|
||||||
.filter(Optional::isPresent)
|
.filter(Optional::isPresent)
|
||||||
.map(Optional::get)
|
.map(Optional::get)
|
||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
|
|
||||||
values.put("permissions", serializePermissions(results));
|
values.put("permissions", serializePermissions(results));
|
||||||
writeMapToFile(file, values);
|
writeMapToFile(file, values);
|
||||||
|
return true;
|
||||||
|
}, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -154,7 +160,7 @@ public class YAMLBacking extends FlatfileBacking {
|
|||||||
User user = plugin.getUserManager().getOrMake(UserIdentifier.of(uuid, username));
|
User user = plugin.getUserManager().getOrMake(UserIdentifier.of(uuid, username));
|
||||||
user.getIoLock().lock();
|
user.getIoLock().lock();
|
||||||
try {
|
try {
|
||||||
return call(() -> {
|
return call(uuid.toString(), () -> {
|
||||||
File userFile = new File(usersDir, uuid.toString() + ".yml");
|
File userFile = new File(usersDir, uuid.toString() + ".yml");
|
||||||
registerFileAction("users", userFile);
|
registerFileAction("users", userFile);
|
||||||
if (userFile.exists()) {
|
if (userFile.exists()) {
|
||||||
@ -201,7 +207,7 @@ public class YAMLBacking extends FlatfileBacking {
|
|||||||
public boolean saveUser(User user) {
|
public boolean saveUser(User user) {
|
||||||
user.getIoLock().lock();
|
user.getIoLock().lock();
|
||||||
try {
|
try {
|
||||||
return call(() -> {
|
return call(user.getUuid().toString(), () -> {
|
||||||
File userFile = new File(usersDir, user.getUuid().toString() + ".yml");
|
File userFile = new File(usersDir, user.getUuid().toString() + ".yml");
|
||||||
registerFileAction("users", userFile);
|
registerFileAction("users", userFile);
|
||||||
if (!GenericUserManager.shouldSave(user)) {
|
if (!GenericUserManager.shouldSave(user)) {
|
||||||
@ -237,29 +243,32 @@ public class YAMLBacking extends FlatfileBacking {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean cleanupUsers() {
|
public boolean cleanupUsers() {
|
||||||
return call(() -> {
|
return call("null", () -> {
|
||||||
File[] files = usersDir.listFiles((dir, name1) -> name1.endsWith(".yml"));
|
File[] files = usersDir.listFiles((dir, name1) -> name1.endsWith(".yml"));
|
||||||
if (files == null) return false;
|
if (files == null) return false;
|
||||||
|
|
||||||
for (File file : files) {
|
for (File file : files) {
|
||||||
registerFileAction("users", file);
|
call(file.getName(), () -> {
|
||||||
|
registerFileAction("users", file);
|
||||||
|
|
||||||
Map<String, Object> values = readMapFromFile(file);
|
Map<String, Object> values = readMapFromFile(file);
|
||||||
|
|
||||||
Set<NodeModel> nodes = new HashSet<>();
|
Set<NodeModel> nodes = new HashSet<>();
|
||||||
nodes.addAll(deserializePermissions((List<Object>) values.get("permissions")));
|
nodes.addAll(deserializePermissions((List<Object>) values.get("permissions")));
|
||||||
|
|
||||||
boolean shouldDelete = false;
|
boolean shouldDelete = false;
|
||||||
if (nodes.size() == 1) {
|
if (nodes.size() == 1) {
|
||||||
for (NodeModel e : nodes) {
|
for (NodeModel e : nodes) {
|
||||||
// There's only one
|
// There's only one
|
||||||
shouldDelete = e.getPermission().equalsIgnoreCase("group.default") && e.isValue();
|
shouldDelete = e.getPermission().equalsIgnoreCase("group.default") && e.isValue();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (shouldDelete) {
|
if (shouldDelete) {
|
||||||
file.delete();
|
file.delete();
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
|
}, true);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}, false);
|
}, false);
|
||||||
@ -268,27 +277,30 @@ public class YAMLBacking extends FlatfileBacking {
|
|||||||
@Override
|
@Override
|
||||||
public List<HeldPermission<UUID>> getUsersWithPermission(String permission) {
|
public List<HeldPermission<UUID>> getUsersWithPermission(String permission) {
|
||||||
ImmutableList.Builder<HeldPermission<UUID>> held = ImmutableList.builder();
|
ImmutableList.Builder<HeldPermission<UUID>> held = ImmutableList.builder();
|
||||||
boolean success = call(() -> {
|
boolean success = call("null", () -> {
|
||||||
File[] files = usersDir.listFiles((dir, name1) -> name1.endsWith(".yml"));
|
File[] files = usersDir.listFiles((dir, name1) -> name1.endsWith(".yml"));
|
||||||
if (files == null) return false;
|
if (files == null) return false;
|
||||||
|
|
||||||
for (File file : files) {
|
for (File file : files) {
|
||||||
registerFileAction("users", file);
|
call(file.getName(), () -> {
|
||||||
|
registerFileAction("users", file);
|
||||||
|
|
||||||
UUID holder = UUID.fromString(file.getName().substring(0, file.getName().length() - 4));
|
UUID holder = UUID.fromString(file.getName().substring(0, file.getName().length() - 4));
|
||||||
|
|
||||||
Map<String, Object> values = readMapFromFile(file);
|
Map<String, Object> values = readMapFromFile(file);
|
||||||
|
|
||||||
Set<NodeModel> nodes = new HashSet<>();
|
Set<NodeModel> nodes = new HashSet<>();
|
||||||
nodes.addAll(deserializePermissions((List<Object>) values.get("permissions")));
|
nodes.addAll(deserializePermissions((List<Object>) values.get("permissions")));
|
||||||
|
|
||||||
for (NodeModel e : nodes) {
|
for (NodeModel e : nodes) {
|
||||||
if (!e.getPermission().equalsIgnoreCase(permission)) {
|
if (!e.getPermission().equalsIgnoreCase(permission)) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
held.add(NodeHeldPermission.of(holder, e));
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
held.add(NodeHeldPermission.of(holder, e));
|
}, true);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}, false);
|
}, false);
|
||||||
@ -300,7 +312,7 @@ public class YAMLBacking extends FlatfileBacking {
|
|||||||
Group group = plugin.getGroupManager().getOrMake(name);
|
Group group = plugin.getGroupManager().getOrMake(name);
|
||||||
group.getIoLock().lock();
|
group.getIoLock().lock();
|
||||||
try {
|
try {
|
||||||
return call(() -> {
|
return call(name, () -> {
|
||||||
File groupFile = new File(groupsDir, name + ".yml");
|
File groupFile = new File(groupsDir, name + ".yml");
|
||||||
registerFileAction("groups", groupFile);
|
registerFileAction("groups", groupFile);
|
||||||
|
|
||||||
@ -335,7 +347,7 @@ public class YAMLBacking extends FlatfileBacking {
|
|||||||
Group group = plugin.getGroupManager().getOrMake(name);
|
Group group = plugin.getGroupManager().getOrMake(name);
|
||||||
group.getIoLock().lock();
|
group.getIoLock().lock();
|
||||||
try {
|
try {
|
||||||
return call(() -> {
|
return call(name, () -> {
|
||||||
File groupFile = new File(groupsDir, name + ".yml");
|
File groupFile = new File(groupsDir, name + ".yml");
|
||||||
registerFileAction("groups", groupFile);
|
registerFileAction("groups", groupFile);
|
||||||
|
|
||||||
@ -358,7 +370,7 @@ public class YAMLBacking extends FlatfileBacking {
|
|||||||
public boolean saveGroup(Group group) {
|
public boolean saveGroup(Group group) {
|
||||||
group.getIoLock().lock();
|
group.getIoLock().lock();
|
||||||
try {
|
try {
|
||||||
return call(() -> {
|
return call(group.getName(), () -> {
|
||||||
File groupFile = new File(groupsDir, group.getName() + ".yml");
|
File groupFile = new File(groupsDir, group.getName() + ".yml");
|
||||||
registerFileAction("groups", groupFile);
|
registerFileAction("groups", groupFile);
|
||||||
|
|
||||||
@ -385,27 +397,31 @@ public class YAMLBacking extends FlatfileBacking {
|
|||||||
@Override
|
@Override
|
||||||
public List<HeldPermission<String>> getGroupsWithPermission(String permission) {
|
public List<HeldPermission<String>> getGroupsWithPermission(String permission) {
|
||||||
ImmutableList.Builder<HeldPermission<String>> held = ImmutableList.builder();
|
ImmutableList.Builder<HeldPermission<String>> held = ImmutableList.builder();
|
||||||
boolean success = call(() -> {
|
boolean success = call("null", () -> {
|
||||||
File[] files = groupsDir.listFiles((dir, name1) -> name1.endsWith(".yml"));
|
File[] files = groupsDir.listFiles((dir, name1) -> name1.endsWith(".yml"));
|
||||||
if (files == null) return false;
|
if (files == null) return false;
|
||||||
|
|
||||||
for (File file : files) {
|
for (File file : files) {
|
||||||
registerFileAction("groups", file);
|
call(file.getName(), () -> {
|
||||||
|
registerFileAction("groups", file);
|
||||||
|
|
||||||
String holder = file.getName().substring(0, file.getName().length() - 4);
|
String holder = file.getName().substring(0, file.getName().length() - 4);
|
||||||
|
|
||||||
Map<String, Object> values = readMapFromFile(file);
|
Map<String, Object> values = readMapFromFile(file);
|
||||||
|
|
||||||
Set<NodeModel> nodes = new HashSet<>();
|
Set<NodeModel> nodes = new HashSet<>();
|
||||||
nodes.addAll(deserializePermissions((List<Object>) values.get("permissions")));
|
nodes.addAll(deserializePermissions((List<Object>) values.get("permissions")));
|
||||||
|
|
||||||
for (NodeModel e : nodes) {
|
for (NodeModel e : nodes) {
|
||||||
if (!e.getPermission().equalsIgnoreCase(permission)) {
|
if (!e.getPermission().equalsIgnoreCase(permission)) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
held.add(NodeHeldPermission.of(holder, e));
|
||||||
}
|
}
|
||||||
|
|
||||||
held.add(NodeHeldPermission.of(holder, e));
|
return true;
|
||||||
}
|
}, true);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}, false);
|
}, false);
|
||||||
@ -417,7 +433,7 @@ public class YAMLBacking extends FlatfileBacking {
|
|||||||
Track track = plugin.getTrackManager().getOrMake(name);
|
Track track = plugin.getTrackManager().getOrMake(name);
|
||||||
track.getIoLock().lock();
|
track.getIoLock().lock();
|
||||||
try {
|
try {
|
||||||
return call(() -> {
|
return call(name, () -> {
|
||||||
File trackFile = new File(tracksDir, name + ".yml");
|
File trackFile = new File(tracksDir, name + ".yml");
|
||||||
registerFileAction("tracks", trackFile);
|
registerFileAction("tracks", trackFile);
|
||||||
|
|
||||||
@ -450,7 +466,7 @@ public class YAMLBacking extends FlatfileBacking {
|
|||||||
Track track = plugin.getTrackManager().getOrMake(name);
|
Track track = plugin.getTrackManager().getOrMake(name);
|
||||||
track.getIoLock().lock();
|
track.getIoLock().lock();
|
||||||
try {
|
try {
|
||||||
return call(() -> {
|
return call(name, () -> {
|
||||||
File trackFile = new File(tracksDir, name + ".yml");
|
File trackFile = new File(tracksDir, name + ".yml");
|
||||||
registerFileAction("tracks", trackFile);
|
registerFileAction("tracks", trackFile);
|
||||||
|
|
||||||
@ -471,7 +487,7 @@ public class YAMLBacking extends FlatfileBacking {
|
|||||||
public boolean saveTrack(Track track) {
|
public boolean saveTrack(Track track) {
|
||||||
track.getIoLock().lock();
|
track.getIoLock().lock();
|
||||||
try {
|
try {
|
||||||
return call(() -> {
|
return call(track.getName(), () -> {
|
||||||
File trackFile = new File(tracksDir, track.getName() + ".yml");
|
File trackFile = new File(tracksDir, track.getName() + ".yml");
|
||||||
registerFileAction("tracks", trackFile);
|
registerFileAction("tracks", trackFile);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user