[Apt-got-cvs-commits] apt-got/src/com/debianmirror/mirror/data DebianMirror.java,1.7,1.8 DebianMirro
Status: Beta
Brought to you by:
dun3
From: Tobias H. <du...@bt...> - 2004-06-09 08:02:40
|
Update of /var/lib/cvs/apt-got/apt-got/src/com/debianmirror/mirror/data In directory btfmx2:/tmp/cvs-serv32176/src/com/debianmirror/mirror/data Modified Files: DebianMirror.java DebianMirrorFile.java DebianMirrorFilePool.java DebianMirrorPurger.java DownloadWatcher.java SimpleMirrorFile.java SpecialMirrorFile.java XmlMirrorConf.java Log Message: Updating from sourceforge 0.8 Index: DebianMirrorPurger.java =================================================================== RCS file: /var/lib/cvs/apt-got/apt-got/src/com/debianmirror/mirror/data/DebianMirrorPurger.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** DebianMirrorPurger.java 2 Jun 2004 01:32:51 -0000 1.3 --- DebianMirrorPurger.java 9 Jun 2004 08:01:45 -0000 1.4 *************** *** 47,58 **** } public void run() { - // wait until info is consistent to start - // the first run. - while(!_mirrorInfo.isConsistent()) { - try { - wait(1019); - } catch(Exception e) {} - } while(true) { if(_mirrorStateChange) { //TODO: Make purger an DebianMirrorObserver --- 47,58 ---- } public void run() { while(true) { + // wait until info is consistent to start + // the run. + while(!_mirrorInfo.isConsistent()) { + try { + wait(1019*300); + } catch(Exception e) {} + } if(_mirrorStateChange) { //TODO: Make purger an DebianMirrorObserver *************** *** 68,71 **** --- 68,72 ---- } catch(Exception e) {} } + } } *************** *** 111,114 **** --- 112,116 ---- // or an old debian file. // delete + _logger.info("Purging file = " + file.getAbsolutePath()); file.delete(); } *************** *** 118,121 **** --- 120,124 ---- // isDebianMirrorFile returns false. try { + _logger.info("Purging file = " + file.getAbsolutePath()); ((DebianMirrorFile)_fileCache.get(filePath)).purge(); } catch(Exception e) { *************** *** 158,162 **** public boolean accept(File pathname) { ! return (pathname.isFile() && pathname.canRead() && !pathname.getAbsolutePath().endsWith(".tmp")); } } --- 161,173 ---- public boolean accept(File pathname) { ! if(pathname.isFile()) { ! if(pathname.canRead()) { ! if(pathname.length() == 0) { ! return true; ! } ! return (!pathname.getAbsolutePath().endsWith(".tmp")); ! } ! } ! return false; } } Index: DebianMirrorFilePool.java =================================================================== RCS file: /var/lib/cvs/apt-got/apt-got/src/com/debianmirror/mirror/data/DebianMirrorFilePool.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** DebianMirrorFilePool.java 2 Jun 2004 01:32:51 -0000 1.11 --- DebianMirrorFilePool.java 9 Jun 2004 08:01:45 -0000 1.12 *************** *** 115,118 **** --- 115,120 ---- mf = createMirrorFile(fileName); _fileCache.put(fileName, mf); + } else { + _logger.fine("FileCache had a file for " + fileName); } } // end of synchronized(_fileCache) *************** *** 120,123 **** --- 122,126 ---- } else { // create uncached/unregistered remotefile + _logger.fine("Return " + fileName + " as uncacheable file"); mf = new UncachedMirrorFile(this, fileName); } Index: DebianMirrorFile.java =================================================================== RCS file: /var/lib/cvs/apt-got/apt-got/src/com/debianmirror/mirror/data/DebianMirrorFile.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** DebianMirrorFile.java 2 Jun 2004 01:32:51 -0000 1.7 --- DebianMirrorFile.java 9 Jun 2004 08:01:45 -0000 1.8 *************** *** 43,47 **** private MirrorModuleConf config; private URL mysite; - private URLConnection connection; private String remoteServer; private String fileName; --- 43,46 ---- *************** *** 76,79 **** --- 75,81 ---- */ public void connect() throws java.io.FileNotFoundException, java.net.MalformedURLException,java.io.IOException { + URLConnection connection; + + setState(MirrorFileState.DOWNLOADING); mysite = _filePool.getMirrorInfo().translatePathToURL(fileName); connection = mysite.openConnection(); *************** *** 84,89 **** logger.finest("length: " + getLength() + " mimeType: " + getMimeType() + " lastMod: " + getLastModified()); ! downloadWatcher = new DownloadWatcher(this, connection, localFile); downloadWatcher.start(); } --- 86,93 ---- logger.finest("length: " + getLength() + " mimeType: " + getMimeType() + " lastMod: " + getLastModified()); ! downloadWatcher = new DownloadWatcher(this, connection, localFile, logger); downloadWatcher.start(); + connection = null; + logger.finest("Done;"); } Index: SpecialMirrorFile.java =================================================================== RCS file: /var/lib/cvs/apt-got/apt-got/src/com/debianmirror/mirror/data/SpecialMirrorFile.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** SpecialMirrorFile.java 2 Jun 2004 01:32:51 -0000 1.5 --- SpecialMirrorFile.java 9 Jun 2004 08:01:45 -0000 1.6 *************** *** 314,322 **** fos.flush(); _logger.finer("Release file " + f.getAbsolutePath() + " finished downloading"); - setState(MirrorFileState.LOCAL); if (!tempFile.renameTo(f)) { throw new IOException("Renaming of the file " + tempFile.getAbsolutePath() + " to " + f.getAbsolutePath() + " failed!"); } f.setLastModified(_lastModified); _logger.fine("Release file " + f.getAbsolutePath() + " successfully downloaded"); --- 314,323 ---- fos.flush(); _logger.finer("Release file " + f.getAbsolutePath() + " finished downloading"); if (!tempFile.renameTo(f)) { throw new IOException("Renaming of the file " + tempFile.getAbsolutePath() + " to " + f.getAbsolutePath() + " failed!"); } + setState(MirrorFileState.LOCAL); + f.setLastModified(_lastModified); _logger.fine("Release file " + f.getAbsolutePath() + " successfully downloaded"); Index: DebianMirror.java =================================================================== RCS file: /var/lib/cvs/apt-got/apt-got/src/com/debianmirror/mirror/data/DebianMirror.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** DebianMirror.java 2 Jun 2004 01:32:51 -0000 1.7 --- DebianMirror.java 9 Jun 2004 08:01:45 -0000 1.8 *************** *** 188,191 **** --- 188,195 ---- return false; } + if(path.indexOf("?") > -1) { + // can't do it! + return false; + } // every thing else should be at least be simple mirrored. return true; Index: XmlMirrorConf.java =================================================================== RCS file: /var/lib/cvs/apt-got/apt-got/src/com/debianmirror/mirror/data/XmlMirrorConf.java,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 Index: DownloadWatcher.java =================================================================== RCS file: /var/lib/cvs/apt-got/apt-got/src/com/debianmirror/mirror/data/DownloadWatcher.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** DownloadWatcher.java 2 Jun 2004 01:32:51 -0000 1.5 --- DownloadWatcher.java 9 Jun 2004 08:01:45 -0000 1.6 *************** *** 34,37 **** --- 34,38 ---- import java.nio.channels.*; import java.util.Iterator; + import java.util.logging.Logger; class DownloadWatcher extends Thread { *************** *** 44,52 **** private int _fileSize; private boolean _useChannels; DownloadWatcher(MirrorFile mf, URLConnection connection, ! File localFile) { _parent = mf; _connection = connection; _fileSize = _connection.getContentLength(); --- 45,57 ---- private int _fileSize; private boolean _useChannels; + private Logger _logger; DownloadWatcher(MirrorFile mf, URLConnection connection, ! File localFile, ! Logger log) { _parent = mf; + _logger = log; + _logger.finest("Entering;"); _connection = connection; _fileSize = _connection.getContentLength(); *************** *** 72,75 **** --- 77,81 ---- public InputStream getInputStream() { + _logger.finest("Entering;"); try { if(_useChannels) { *************** *** 82,85 **** --- 88,92 ---- _pipeList.add(new CountingChannel((WritableByteChannel)sink)); } + _logger.finer("Returning as channel"); return Channels.newInputStream((ReadableByteChannel)source); } else { *************** *** 90,93 **** --- 97,101 ---- _pipeList.add(pair); } + _logger.finer("Returning as pipe"); return pis; } *************** *** 161,170 **** } // download finished ! map.force(); ! if (!_tempFile.renameTo(_localFile)) { ! _parent.setState(MirrorFileState.UNKNOWN); ! throw new java.io.IOException("Renaming of the file " + _localFile.getAbsolutePath() + " failed!"); ! } ! _parent.setState(MirrorFileState.LOCAL); // finalize sending data while(_pipeList.size() > 0) { --- 169,181 ---- } // download finished ! map.force(); ! if (!_tempFile.renameTo(_localFile)) { ! _parent.setState(MirrorFileState.UNKNOWN); ! throw new java.io.IOException("Renaming of the file " + _localFile.getAbsolutePath() + " failed!"); ! } ! _parent.setState(MirrorFileState.LOCAL); ! try { ! _localFile.setLastModified(_connection.getLastModified()); ! } catch(Exception ignore) {} // finalize sending data while(_pipeList.size() > 0) { *************** *** 177,181 **** channelPos = sink.getPosition(); temp = downloadPos - channelPos; ! if(_pipeList.size() == 1) { // if we are the only one in the list --- 188,192 ---- channelPos = sink.getPosition(); temp = downloadPos - channelPos; ! if(_pipeList.size() == 1) { // if we are the only one in the list *************** *** 282,286 **** throw new java.io.IOException("Renaming of the file " + _localFile + " failed!"); } ! // finalize all sending // --- 293,299 ---- throw new java.io.IOException("Renaming of the file " + _localFile + " failed!"); } ! try { ! _localFile.setLastModified(_connection.getLastModified()); ! } catch(Exception ignore) {} // finalize all sending // Index: SimpleMirrorFile.java =================================================================== RCS file: /var/lib/cvs/apt-got/apt-got/src/com/debianmirror/mirror/data/SimpleMirrorFile.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** SimpleMirrorFile.java 2 Jun 2004 01:32:51 -0000 1.2 --- SimpleMirrorFile.java 9 Jun 2004 08:01:45 -0000 1.3 *************** *** 23,74 **** import java.net.URL; import java.util.Date; public class SimpleMirrorFile implements MirrorFile { ! private URLConnection _connection; public SimpleMirrorFile(MirrorFilePool mfp, String path) throws IOException { ! _connection = mfp.getMirrorInfo().translatePathToURL(path).openConnection(); } public InputStream getInputStream() { try { ! return _connection.getInputStream(); ! } catch (IOException ioe) { ! return null; ! } catch (NullPointerException npe) { return null; } } public long getLength() { ! try { ! return _connection.getContentLength(); ! } catch(NullPointerException npe) { ! return -1; ! } } public String getMimeType() { ! try { ! return _connection.getContentType(); ! } catch(NullPointerException npe) { ! return null; ! } } public long getLastModified() { ! try { ! return _connection.getLastModified(); ! } catch(NullPointerException npe) { ! return (new Date()).getTime(); ! } } public void purge() { ! // nothing can be done here } public void setState(MirrorFileState mfs) { ! // nothing to do } public MirrorFileState getState() { ! return MirrorFileState.DOWNLOADING; } public void checkState() { ! // nothing to do } --- 23,113 ---- import java.net.URL; import java.util.Date; + import java.util.logging.Level; + import java.util.logging.Logger; + import java.io.IOException; + import java.io.FileOutputStream; + import java.io.FileInputStream; + import java.io.BufferedInputStream; + import java.io.File; public class SimpleMirrorFile implements MirrorFile { ! private MirrorFilePool _filePool; ! ! private long _lastModified; ! private String _mimeType; ! private long _length; ! ! private URL _url; ! ! private Logger _logger; ! ! private MirrorFileState _fileState; ! private Object _stateLock; + private File _localFile; + public SimpleMirrorFile(MirrorFilePool mfp, String path) throws IOException { ! _filePool = mfp; ! _url = _filePool.getMirrorInfo().translatePathToURL(path); ! ! _stateLock = new Object(); ! _fileState = MirrorFileState.PENDING; ! ! _logger = Logger.getLogger(_filePool.getConfig().getLoggerNamespace()); ! ! _localFile = _filePool.translatePathToFile(path); ! checkState(); } + public InputStream getInputStream() { try { ! checkState(); ! return new FileInputStream(_localFile); ! } catch (Exception e) { ! setState(MirrorFileState.UNKNOWN); return null; } } public long getLength() { ! return _length; } public String getMimeType() { ! return _mimeType; } public long getLastModified() { ! return _lastModified; } public void purge() { ! _logger.finest("Entering;"); ! // we have to synchronize all the way... ! synchronized(_stateLock) { ! setState(MirrorFileState.PURGED); ! try { ! _localFile.delete(); ! } catch(Exception e) {} ! } } public void setState(MirrorFileState mfs) { ! synchronized(_stateLock) { ! _fileState = mfs; ! } } public MirrorFileState getState() { ! synchronized(_stateLock) { ! return _fileState; ! } } public void checkState() { ! try { ! if (!_localFile.isFile()) { ! _logger.finer(_localFile.getAbsolutePath() + ": Starting download"); ! downloadFile(); ! } else { ! setState(MirrorFileState.LOCAL); ! } ! } catch(Exception e) { ! _logger.log(Level.INFO, "Threw exception - setting state to UNKNOWN", e); ! setState(MirrorFileState.UNKNOWN); ! } } *************** *** 84,86 **** --- 123,186 ---- return true; } + + private synchronized void downloadFile() throws IOException { + _logger.finest("Entering;"); + setState(MirrorFileState.DOWNLOADING); + File tempFile = null; + FileOutputStream fos = null; + BufferedInputStream bis = null; + + try { + _localFile.delete(); + URLConnection conn = _url.openConnection(); + _mimeType = conn.getContentType(); + _lastModified = conn.getLastModified(); + _length = conn.getContentLength(); + + tempFile = File.createTempFile("apt", ".tmp", _localFile.getParentFile()); + if(_lastModified == 0) { + // last modidied was unknow for that connection. + _lastModified = (new Date()).getTime(); + } + fos = new FileOutputStream(tempFile); + bis = new BufferedInputStream(conn.getInputStream()); + byte[] buf = new byte[64]; + int b = bis.read(buf, 0, buf.length); + while(b > -1){ + fos.write(buf, 0, b); + b = bis.read(buf, 0, buf.length); + } + fos.flush(); + _logger.finer("Simple file " + _localFile.getAbsolutePath() + " finished downloading"); + if (!tempFile.renameTo(_localFile)) { + throw new IOException("Renaming of the file " + tempFile.getAbsolutePath() + " to " + _localFile.getAbsolutePath() + " failed!"); + } + setState(MirrorFileState.LOCAL); + try { + _localFile.setLastModified(_lastModified); + } catch(Exception ignore) {} + _length = _localFile.length(); + _logger.fine("Simple file " + _localFile.getAbsolutePath() + " successfully downloaded"); + } catch(IOException ioe) { + _logger.log(Level.FINE, "Caught IOException", ioe); + try { + purge(); + tempFile.delete(); + fos.close(); + bis.close(); + } catch(Exception e) { + // ignore + } + setState(MirrorFileState.UNKNOWN); + throw ioe; + } finally { + try { + fos.close(); + } catch(Exception e) {} + try { + bis.close(); + } catch(Exception e) {} + } + } + } |