mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-08-29 16:47:56 +00:00
Don't close file handles from ResourceMounts
Unlike short handles, we don't read these immediately, and so we can't close it right away. Otherwise the file is considered empty! Fixes SquidDev-CC/treasure-programs#1
This commit is contained in:
@@ -31,7 +31,7 @@ import com.google.common.io.ByteStreams;
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.api.filesystem.IMount;
|
||||
import dan200.computercraft.core.apis.handles.ArrayByteChannel;
|
||||
|
||||
import dan200.computercraft.shared.util.IoUtil;
|
||||
import net.minecraft.resource.ReloadableResourceManager;
|
||||
import net.minecraft.resource.Resource;
|
||||
import net.minecraft.resource.ResourceManager;
|
||||
@@ -186,13 +186,19 @@ public final class ResourceMount implements IMount {
|
||||
return new ArrayByteChannel(contents);
|
||||
}
|
||||
|
||||
try (InputStream stream = this.manager.getResource(file.identifier)
|
||||
.getInputStream()) {
|
||||
if (stream.available() > MAX_CACHED_SIZE) {
|
||||
return Channels.newChannel(stream);
|
||||
}
|
||||
try
|
||||
{
|
||||
InputStream stream = manager.getResource( file.identifier ).getInputStream();
|
||||
if( stream.available() > MAX_CACHED_SIZE ) return Channels.newChannel( stream );
|
||||
|
||||
contents = ByteStreams.toByteArray(stream);
|
||||
try
|
||||
{
|
||||
contents = ByteStreams.toByteArray( stream );
|
||||
}
|
||||
finally
|
||||
{
|
||||
IoUtil.closeQuietly( stream );
|
||||
}
|
||||
CONTENTS_CACHE.put(file, contents);
|
||||
return new ArrayByteChannel(contents);
|
||||
} catch (FileNotFoundException ignored) {
|
||||
|
Reference in New Issue
Block a user