Changeset 127aebe


Ignore:
Timestamp:
Jul 18, 2011 2:07:56 PM (10 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
3f8df84
Parents:
dbaa659 (diff), a8378d0 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

merge of '5985a037ecd49475ed49c120a5ab9d898f058fe6'

and 'adba1e5ca6162b93d450aee8fd7e723bac51abf0'

Files:
8 edited

Legend:

Unmodified
Added
Removed
  • apps/i2ptunnel/java/src/net/i2p/i2ptunnel/web/IndexBean.java

    rdbaa659 r127aebe  
    99 */
    1010
     11import java.io.File;
    1112import java.io.IOException;
    1213import java.util.ArrayList;
     
    3132import net.i2p.i2ptunnel.TunnelControllerGroup;
    3233import net.i2p.util.ConcurrentHashSet;
     34import net.i2p.util.FileUtil;
    3335import net.i2p.util.Log;
    3436
     
    4143 */
    4244public class IndexBean {
    43     protected I2PAppContext _context;
    44     protected Log _log;
    45     protected TunnelControllerGroup _group;
     45    protected final I2PAppContext _context;
     46    protected final Log _log;
     47    protected final TunnelControllerGroup _group;
    4648    private String _action;
    4749    private int _tunnel;
     
    7577    private boolean _privKeyGenerate;
    7678    private boolean _removeConfirmed;
    77     private Set<String> _booleanOptions;
    78     private Map<String, String> _otherOptions;
     79    private final Set<String> _booleanOptions;
     80    private final Map<String, String> _otherOptions;
    7981    private int _hashCashValue;
    8082    private int _certType;
     
    199201    private String stopAll() {
    200202        if (_group == null) return "";
    201         List msgs = _group.stopAllControllers();
     203        List<String> msgs = _group.stopAllControllers();
    202204        return getMessages(msgs);
    203205    }
    204206    private String startAll() {
    205207        if (_group == null) return "";
    206         List msgs = _group.startAllControllers();
     208        List<String> msgs = _group.startAllControllers();
    207209        return getMessages(msgs);
    208210    }
    209211    private String restartAll() {
    210212        if (_group == null) return "";
    211         List msgs = _group.restartAllControllers();
     213        List<String> msgs = _group.restartAllControllers();
    212214        return getMessages(msgs);
    213215    }
     
    317319    }
    318320
     321    /**
     322     *  Stop the tunnel, delete from config,
     323     *  rename the private key file if in the default directory
     324     */
    319325    private String deleteTunnel() {
    320326        if (!_removeConfirmed)
     
    325331            return "Invalid tunnel number";
    326332       
    327         List msgs = _group.removeController(cur);
     333        List<String> msgs = _group.removeController(cur);
    328334        msgs.addAll(doSave());
     335
     336        // Rename private key file if it was a default name in
     337        // the default directory, so it doesn't get reused when a new
     338        // tunnel is created.
     339        // Use configured file name if available, not the one from the form.
     340        String pk = cur.getPrivKeyFile();
     341        if (pk == null)
     342            pk = _privKeyFile;
     343        if (pk != null && pk.startsWith("i2ptunnel") && pk.endsWith("-privKeys.dat")) {
     344            File pkf = new File(_context.getConfigDir(), pk);
     345            if (pkf.exists()) {
     346                String name = cur.getName();
     347                if (name == null) {
     348                    name = cur.getDescription();
     349                    if (name == null) {
     350                        name = cur.getType();
     351                        if (name == null)
     352                            name = Long.toString(_context.clock().now());
     353                    }
     354                }
     355                name = "i2ptunnel-deleted-" + name.replace(' ', '_') + "-privkeys.dat";
     356                File to = new File(_context.getConfigDir(), name);
     357                if (to.exists())
     358                    to = new File(_context.getConfigDir(), name + '-' + _context.clock().now());
     359                boolean success = FileUtil.rename(pkf, to);
     360                if (success)
     361                    msgs.add("Private key file " + pkf.getAbsolutePath() +
     362                             " renamed to " + to.getAbsolutePath());
     363            }
     364        }
    329365        return getMessages(msgs);
    330366    }
  • apps/routerconsole/java/src/net/i2p/router/web/NewsFetcher.java

    rdbaa659 r127aebe  
    360360        long now = _context.clock().now();
    361361        if (_tempFile.exists()) {
    362             boolean copied = FileUtil.copy(_tempFile.getAbsolutePath(), _newsFile.getAbsolutePath(), true);
     362            boolean copied = FileUtil.copy(_tempFile, _newsFile, true, false);
    363363            if (copied) {
    364364                _lastUpdated = now;
  • apps/routerconsole/java/src/net/i2p/router/web/UnsignedUpdateHandler.java

    rdbaa659 r127aebe  
    9494                return;
    9595            }
    96             String to = (new File(_context.getRouterDir(), Router.UPDATE_FILE)).getAbsolutePath();
    97             boolean copied = FileUtil.copy(_updateFile, to, true);
     96            File to = new File(_context.getRouterDir(), Router.UPDATE_FILE);
     97            boolean copied = FileUtil.copy(updFile, to, true, false);
    9898            if (copied) {
    9999                updFile.delete();
     
    125125            } else {
    126126                _log.log(Log.CRIT, "Failed copy to " + to);
    127                 updateStatus("<b>" + _("Failed copy to {0}", to) + "</b>");
     127                updateStatus("<b>" + _("Failed copy to {0}", to.getAbsolutePath()) + "</b>");
    128128            }
    129129        }
  • core/java/src/freenet/support/CPUInformation/CPUID.java

    rdbaa659 r127aebe  
    403403        // copy to install dir, ignore failure
    404404        File newFile = new File(I2PAppContext.getGlobalContext().getBaseDir(), filename);
    405         FileUtil.copy(outFile.getAbsolutePath(), newFile.getAbsolutePath(), false, true);
     405        FileUtil.copy(outFile, newFile, false, true);
    406406        return true;
    407407    }
  • core/java/src/net/i2p/client/naming/SingleFileNamingService.java

    rdbaa659 r127aebe  
    194194            out.newLine();
    195195            out.close();
    196             boolean success = rename(tmp, _file);
     196            boolean success = FileUtil.rename(tmp, _file);
    197197            if (success) {
    198198                for (NamingServiceListener nsl : _listeners) {
     
    285285                return false;
    286286            }
    287             success = rename(tmp, _file);
     287            success = FileUtil.rename(tmp, _file);
    288288            if (success) {
    289289                for (NamingServiceListener nsl : _listeners) {
     
    441441            releaseWriteLock();
    442442        }
    443     }
    444 
    445     private static boolean rename(File from, File to) {
    446         boolean success = false;
    447         boolean isWindows = System.getProperty("os.name").startsWith("Win");
    448         // overwrite fails on windows
    449         if (!isWindows)
    450             success = from.renameTo(to);
    451         if (!success) {
    452             to.delete();
    453             success = from.renameTo(to);
    454             if (!success) {
    455                 // hard way
    456                 success = FileUtil.copy(from.getAbsolutePath(), to.getAbsolutePath(), true, true);
    457                 from.delete();
    458             }
    459         }
    460         return success;
    461443    }
    462444
  • core/java/src/net/i2p/util/FileUtil.java

    rdbaa659 r127aebe  
    401401        File src = new File(source);
    402402        File dst = new File(dest);
    403 
     403        return copy(src, dst, overwriteExisting, quiet);
     404    }
     405
     406    /**
     407      * @param quiet don't log fails to wrapper log if true
     408      * @return true if it was copied successfully
     409      * @since 0.8.8
     410      */
     411    public static boolean copy(File src, File dst, boolean overwriteExisting, boolean quiet) {
    404412        if (dst.exists() && dst.isDirectory())
    405413            dst = new File(dst, src.getName());
     
    430438    }
    431439   
     440    /**
     441     * Try to rename, if it doesn't work then copy and delete the old.
     442     * Always overwrites any existing "to" file.
     443     * Method moved from SingleFileNamingService.
     444     *
     445     * @return true if it was renamed / copied successfully
     446     * @since 0.8.8
     447     */
     448    public static boolean rename(File from, File to) {
     449        if (!from.exists())
     450            return false;
     451        boolean success = false;
     452        boolean isWindows = System.getProperty("os.name").startsWith("Win");
     453        // overwrite fails on windows
     454        if (!isWindows)
     455            success = from.renameTo(to);
     456        if (!success) {
     457            to.delete();
     458            success = from.renameTo(to);
     459            if (!success) {
     460                // hard way
     461                success = copy(from, to, true, true);
     462                if (success)
     463                    from.delete();
     464            }
     465        }
     466        return success;
     467    }
     468
    432469    /**
    433470     * Usage: FileUtil (delete path | copy source dest | unzip path.zip)
  • core/java/src/net/i2p/util/NativeBigInteger.java

    rdbaa659 r127aebe  
    607607        // copy to install dir, ignore failure
    608608        File newFile = new File(I2PAppContext.getGlobalContext().getBaseDir(), filename);
    609         FileUtil.copy(outFile.getAbsolutePath(), newFile.getAbsolutePath(), false, true);
     609        FileUtil.copy(outFile, newFile, false, true);
    610610        return true;
    611611    }
  • router/java/src/net/i2p/router/transport/udp/UDPEndpoint.java

    rdbaa659 r127aebe  
    8181********/
    8282   
    83     /** 8998 is monotone, and 32000 is the wrapper, so let's stay between those */
     83    /** 8998 is monotone, and 31000 is the wrapper outbound, so let's stay between those */
    8484    public static final String PROP_MIN_PORT = "i2np.udp.minPort";
    8585    public static final String PROP_MAX_PORT = "i2np.udp.maxPort";
    8686    private static final int MIN_RANDOM_PORT = 9111;
    87     private static final int MAX_RANDOM_PORT = 31777;
     87    private static final int MAX_RANDOM_PORT = 30777;
    8888    private static final int MAX_PORT_RETRIES = 20;
    8989
Note: See TracChangeset for help on using the changeset viewer.