2007-09-19 zzz

* i2psnark: Fix broken multifile torrent Delete;
        cleanup Storage resources in AddTorrent;
        don't autostart torrent after Create
This commit is contained in:
zzz
2007-09-20 01:44:02 +00:00
committed by zzz
parent b772179077
commit 9145eedc35
4 changed files with 38 additions and 21 deletions

View File

@ -117,7 +117,8 @@ public class Storage
}
String name = baseFile.getName();
if (files.size() == 1)
if (files.size() == 1) // FIXME: ...and if base file not a directory or should this be the only check?
// this makes a bad metainfo if the directory has only one file in it
{
files = null;
lengthsList = null;
@ -406,7 +407,7 @@ public class Storage
/**
* Removes 'suspicious' characters from the give file name.
*/
private String filterName(String name)
private static String filterName(String name)
{
// XXX - Is this enough?
return name.replace(File.separatorChar, '_');
@ -438,7 +439,7 @@ public class Storage
return f;
}
private File getFileFromNames(File base, List names) throws IOException
public static File getFileFromNames(File base, List names)
{
Iterator it = names.iterator();
while (it.hasNext())

View File

@ -248,23 +248,31 @@ public class I2PSnarkServlet extends HttpServlet {
_manager.addMessage("Torrent file deleted: " + f.getAbsolutePath());
List files = snark.meta.getFiles();
String dataFile = snark.meta.getName();
for (int i = 0; files != null && i < files.size(); i++) {
// multifile torrents have the getFiles() return lists of lists of filenames, but
// each of those lists just contain a single file afaict...
File df = new File(_manager.getDataDir(), files.get(i).toString());
boolean deleted = FileUtil.rmdir(df, false);
if (deleted)
_manager.addMessage("Data dir deleted: " + df.getAbsolutePath());
else
_manager.addMessage("Data dir could not be deleted: " + df.getAbsolutePath());
}
if (dataFile != null) {
f = new File(_manager.getDataDir(), dataFile);
boolean deleted = f.delete();
if (deleted)
f = new File(_manager.getDataDir(), dataFile);
if (files == null) { // single file torrent
if (f.delete())
_manager.addMessage("Data file deleted: " + f.getAbsolutePath());
else
_manager.addMessage("Data file could not be deleted: " + f.getAbsolutePath());
break;
}
for (int i = 0; i < files.size(); i++) { // pass 1 delete files
// multifile torrents have the getFiles() return lists of lists of filenames, but
// each of those lists just contain a single file afaict...
File df = Storage.getFileFromNames(f, (List) files.get(i));
if (df.delete())
_manager.addMessage("Data file deleted: " + df.getAbsolutePath());
else
_manager.addMessage("Data file could not be deleted: " + df.getAbsolutePath());
}
for (int i = files.size() - 1; i >= 0; i--) { // pass 2 delete dirs - not foolproof,
// we could sort and do a strict bottom-up
File df = Storage.getFileFromNames(f, (List) files.get(i));
df = df.getParentFile();
if (df == null || !df.exists())
continue;
if(df.delete())
_manager.addMessage("Data dir deleted: " + df.getAbsolutePath());
}
break;
}
@ -297,16 +305,19 @@ public class I2PSnarkServlet extends HttpServlet {
try {
Storage s = new Storage(baseFile, announceURL, null);
s.create();
s.close(); // close the files... maybe need a way to pass this Storage to addTorrent rather than starting over
MetaInfo info = s.getMetaInfo();
File torrentFile = new File(baseFile.getParent(), baseFile.getName() + ".torrent");
if (torrentFile.exists())
throw new IOException("Cannot overwrite an existing .torrent file: " + torrentFile.getPath());
_manager.saveTorrentStatus(info, s.getBitField()); // so addTorrent won't recheck
// DirMonitor could grab this first, maybe hold _snarks lock?
FileOutputStream out = new FileOutputStream(torrentFile);
out.write(info.getTorrentData());
out.close();
_manager.addMessage("Torrent created for " + baseFile.getName() + ": " + torrentFile.getAbsolutePath());
// now fire it up, but don't automatically seed it
_manager.addTorrent(torrentFile.getCanonicalPath(), false);
_manager.addTorrent(torrentFile.getCanonicalPath(), true);
_manager.addMessage("Many I2P trackers require you to register new torrents before seeding - please do so before starting " + baseFile.getName());
} catch (IOException ioe) {
_manager.addMessage("Error creating a torrent for " + baseFile.getAbsolutePath() + ": " + ioe.getMessage());

View File

@ -1,4 +1,9 @@
$Id: history.txt,v 1.587 2007-09-14 20:58:30 zzz Exp $
$Id: history.txt,v 1.588 2007-09-18 14:09:21 zzz Exp $
2007-09-19 zzz
* i2psnark: Fix broken multifile torrent Delete;
cleanup Storage resources in AddTorrent;
don't autostart torrent after Create
2007-09-18 zzz
* eepsite_index.html: Add links to trevorreznik address book

View File

@ -15,9 +15,9 @@ import net.i2p.CoreVersion;
*
*/
public class RouterVersion {
public final static String ID = "$Revision: 1.523 $ $Date: 2007-09-14 20:58:30 $";
public final static String ID = "$Revision: 1.524 $ $Date: 2007-09-18 14:09:19 $";
public final static String VERSION = "0.6.1.29";
public final static long BUILD = 5;
public final static long BUILD = 6;
public static void main(String args[]) {
System.out.println("I2P Router version: " + VERSION + "-" + BUILD);
System.out.println("Router ID: " + RouterVersion.ID);