Changeset 196


Ignore:
Timestamp:
11/04/02 15:32:22 (21 years ago)
Author:
piso
Message:

makeBackup(): if copyFile() fails because the existing backup file is not
writable, delete that file and try again.

File:
1 edited

Legend:

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

    r73 r196  
    33 *
    44 * Copyright (C) 1998-2002 Peter Graves
    5  * $Id: Utilities.java,v 1.2 2002-10-10 16:26:59 piso Exp $
     5 * $Id: Utilities.java,v 1.3 2002-11-04 15:32:22 piso Exp $
    66 *
    77 * This program is free software; you can redistribute it and/or
     
    964964    {
    965965        // No need to back it up if it doesn't exist.
    966         if (!file.exists())
     966        if (!file.isFile())
    967967            return true;
    968968        File backupDir = null;
     
    973973        } else {
    974974            // Use default location.
    975             backupDir = File.getInstance(Editor.getUserHomeDirectory(), "backup");
     975            backupDir = File.getInstance(Directories.getUserHomeDirectory(),
     976                                         "backup");
    976977        }
    977978        if (backupDir == null)
    978979            return false;
    979         if (!backupDir.exists() && !backupDir.mkdirs()) {
     980        if (!backupDir.isDirectory() && !backupDir.mkdirs()) {
    980981            Log.error("can't create backup directory ".concat(backupDir.canonicalPath()));
    981982            return false;
     
    988989                return true;
    989990        }
    990         if (copyFile(file, backupFile)) {
     991        if (copyFile(file, backupFile))
    991992            return true;
     993        // If copyFile() failed because the existing backup file is not
     994        // writable, delete that file and try again.
     995        if (backupFile.isFile() && !backupFile.canWrite()) {
     996            Log.debug("deleting old backup file " + backupFile);
     997            backupFile.delete();
     998            Log.debug("retrying copyFile...");
     999            if (copyFile(file, backupFile))
     1000                return true;
    9921001        }
    9931002        Log.error("makeBackup copyFile failed, returning false");
Note: See TracChangeset for help on using the changeset viewer.