diff --git a/apps/i2psnark/java/src/org/klomp/snark/Storage.java b/apps/i2psnark/java/src/org/klomp/snark/Storage.java index 7dc1fa1c8..e330b40ab 100644 --- a/apps/i2psnark/java/src/org/klomp/snark/Storage.java +++ b/apps/i2psnark/java/src/org/klomp/snark/Storage.java @@ -256,7 +256,10 @@ public class Storage rafs = new RandomAccessFile[1]; names = new String[1]; lengths[0] = metainfo.getTotalLength(); - rafs[0] = new RandomAccessFile(base, "rw"); + if (base.exists() && !base.canWrite()) // hope we can get away with this, if we are only seeding... + rafs[0] = new RandomAccessFile(base, "r"); + else + rafs[0] = new RandomAccessFile(base, "rw"); names[0] = base.getName(); } else @@ -277,7 +280,10 @@ public class Storage File f = createFileFromNames(base, (List)files.get(i)); lengths[i] = ((Long)ls.get(i)).longValue(); total += lengths[i]; - rafs[i] = new RandomAccessFile(f, "rw"); + if (f.exists() && !f.canWrite()) // see above re: only seeding + rafs[i] = new RandomAccessFile(f, "r"); + else + rafs[i] = new RandomAccessFile(f, "rw"); names[i] = f.getName(); } @@ -402,6 +408,7 @@ public class Storage */ public void close() throws IOException { + if (rafs == null) return; for (int i = 0; i < rafs.length; i++) { try { diff --git a/history.txt b/history.txt index e6408c8cf..131e57a48 100644 --- a/history.txt +++ b/history.txt @@ -1,4 +1,8 @@ -$Id: history.txt,v 1.357 2005/12/15 22:00:48 jrandom Exp $ +$Id: history.txt,v 1.358 2005/12/16 03:24:22 jrandom Exp $ + +2005-12-16 jrandom + * Try to run a torrent in readonly mode if we can't write to the file, and + handle failures a little more gracefully (thanks polecat!) 2005-12-16 jrandom * Refuse torrents with too many files (128), avoiding ulimit errors.