Changeset 5079


Ignore:
Timestamp:
2003-08-04T11:32:49+12:00 (21 years ago)
Author:
jmt12
Message:

A file permission error is now correctly shown when you attempt to copy a file to a read-only folder (rather than a source file not found one)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/file/FileQueue.java

    r4675 r5079  
    1 package org.greenstone.gatherer.file;
    21/**
    32 *#########################################################################
     
    76 * University of Waikato, New Zealand.
    87 *
    9  * <BR><BR>
    10  *
    118 * Author: John Thompson, Greenstone Digital Library, University of Waikato
    129 *
    13  * <BR><BR>
    14  *
    1510 * Copyright (C) 1999 New Zealand Digital Library Project
    16  *
    17  * <BR><BR>
    1811 *
    1912 * This program is free software; you can redistribute it and/or modify
     
    2215 * (at your option) any later version.
    2316 *
    24  * <BR><BR>
    25  *
    2617 * This program is distributed in the hope that it will be useful,
    2718 * but WITHOUT ANY WARRANTY; without even the implied warranty of
    2819 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    2920 * GNU General Public License for more details.
    30  *
    31  * <BR><BR>
    3221 *
    3322 * You should have received a copy of the GNU General Public License
     
    3625 *########################################################################
    3726 */
     27package org.greenstone.gatherer.file;
     28
    3829import java.io.*;
    3930import java.util.*;
     
    327318                    // Nothing else we can do.
    328319                }
     320                catch(WriteNotPermittedException wnp_exception) {
     321                    Gatherer.printStackTrace(wnp_exception);
     322                    cancel_action = true;
     323                    // Show warning
     324                    JOptionPane.showMessageDialog(Gatherer.g_man, get("Write_Not_Permitted_Message", target_file.getAbsolutePath()), get("Write_Not_Permitted_Title"), JOptionPane.ERROR_MESSAGE);
     325                    // Nothing else we can do.
     326                }
    329327                catch(IOException exception) {
    330328                    // Can't really do much about this.
     
    669667      */
    670668    public void copyFile(File source, File destination, LongProgressBar progress)
    671     throws FileAlreadyExistsException, FileNotFoundException, InsufficientSpaceException, IOException, UnknownFileErrorException {
     669    throws FileAlreadyExistsException, FileNotFoundException, InsufficientSpaceException, IOException, UnknownFileErrorException, WriteNotPermittedException {
    672670    if(source.isDirectory()) {
    673671        destination.mkdirs();
     
    676674                // Check if the origin file exists.
    677675        if(!source.exists()) {
     676        System.err.println("Couldn't find the source file.");
    678677        throw(new FileNotFoundException());
    679678        }
     
    686685                // Copy the file.
    687686        FileInputStream f_in = new FileInputStream(source);
    688         FileOutputStream f_out = new FileOutputStream(destination);
     687        FileOutputStream f_out = null;
     688        // This may throw a file not found exception, but this translates to a WriteNotPermittedException, in this case
     689        try {
     690        f_out = new FileOutputStream(destination);
     691        }
     692        catch (FileNotFoundException exception) {
     693        throw new WriteNotPermittedException(exception.toString());
     694        }
    689695        byte data[] = new byte[Utility.BUFFER_SIZE];
    690696        int data_size = 0;
     
    711717        }
    712718        }
    713                 // Flush and close the streams to ensure all bytes are written.
     719        // Flush and close the streams to ensure all bytes are written.
    714720        f_in.close();
    715721        f_out.close();
    716                 // We have now, in theory, produced an exact copy of the source file. Check this by comparing sizes.
    717         if(!cancel_action && source.length() != destination.length()) {
     722        // We have now, in theory, produced an exact copy of the source file. Check this by comparing sizes.
     723        if(!destination.exists() || (!cancel_action && source.length() != destination.length())) {
    718724        throw(new UnknownFileErrorException());
    719725        }
    720                 // If we were cancelled, ensure that none of the destination file exists.
     726        // If we were cancelled, ensure that none of the destination file exists.
    721727        if(cancel_action) {
    722728        destination.delete();
Note: See TracChangeset for help on using the changeset viewer.