Changeset 10030


Ignore:
Timestamp:
09/25/05 20:47:59 (16 years ago)
Author:
piso
Message:

Don't follow symlinks!

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/j/src/org/armedbear/lisp/delete_file.java

    r9059 r10030  
    22 * delete_file.java
    33 *
    4  * Copyright (C) 2003-2004 Peter Graves
    5  * $Id: delete_file.java,v 1.7 2005-05-05 14:33:44 piso Exp $
     4 * Copyright (C) 2003-2005 Peter Graves
     5 * $Id: delete_file.java,v 1.8 2005-09-25 20:47:59 piso Exp $
    66 *
    77 * This program is free software; you can redistribute it and/or
     
    2323
    2424import java.io.File;
     25import java.io.IOException;
    2526
    2627public final class delete_file extends Primitive
     
    3435    public LispObject execute(LispObject arg) throws ConditionThrowable
    3536    {
    36         final LispObject truename = Pathname.truename(arg, false);
     37        // Don't dereference symlinks!
     38        Pathname pathname = Pathname.coerceToPathname(arg);
    3739        if (arg instanceof Stream)
    3840            ((Stream)arg)._close();
    39         if (truename instanceof Pathname) {
     41        if (pathname instanceof LogicalPathname)
     42            pathname = LogicalPathname.translateLogicalPathname((LogicalPathname)pathname);
     43        if (pathname.isWild())
     44            return signal(new FileError("Bad place for a wild pathname.",
     45                                        pathname));
     46        final Pathname defaultedPathname =
     47            Pathname.mergePathnames(pathname,
     48                                    Pathname.coerceToPathname(_DEFAULT_PATHNAME_DEFAULTS_.symbolValue()),
     49                                    NIL);
     50        final String namestring = defaultedPathname.getNamestring();
     51        if (namestring == null)
     52            return signal(new FileError("Pathname has no namestring: " + defaultedPathname.writeToString(),
     53                                        defaultedPathname));
     54        final File file = new File(namestring);
     55        if (file.exists()) {
    4056            // File exists.
    41             File file = Utilities.getFile((Pathname)truename);
    4257            for (int i = 0; i < 5; i++) {
    4358                if (file.delete())
     
    4661                Thread.yield();
    4762            }
    48             StringBuffer sb = new StringBuffer("Unable to delete ");
     63            Pathname truename = new Pathname(file.getAbsolutePath());
     64            FastStringBuffer sb = new FastStringBuffer("Unable to delete ");
    4965            sb.append(file.isDirectory() ? "directory " : "file ");
    5066            sb.append(truename.writeToString());
Note: See TracChangeset for help on using the changeset viewer.