Changeset 8505


Ignore:
Timestamp:
2004-11-10T12:50:45+13:00 (19 years ago)
Author:
mdewsnip
Message:

You now get a sensible error message when attempting to copy a file you don't have permission to read.

Location:
trunk/gli/src/org/greenstone/gatherer/file
Files:
1 added
1 edited

Legend:

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

    r8313 r8505  
    342342                    // Nothing else can be done by the Gatherer. In fact if we are really out of space I'm not even sure we can quit safely.
    343343                    }
     344                    catch (ReadNotPermittedException rnp_exception) {
     345                    if (DebugStream.isDebuggingEnabled()) {
     346                        DebugStream.printStackTrace(rnp_exception);
     347                    }
     348                    cancel_action = true;
     349                    // Show warning
     350                    JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("FileActions.Read_Not_Permitted_Message", source_file.getAbsolutePath()), Dictionary.get("FileActions.Write_Not_Permitted_Title"), JOptionPane.ERROR_MESSAGE);
     351                    // Nothing else we can do.
     352                    }
    344353                    catch(UnknownFileErrorException ufe_exception) {
    345354                    DebugStream.printStackTrace(ufe_exception);
     
    350359                    }
    351360                    catch(WriteNotPermittedException wnp_exception) {
    352                     DebugStream.printStackTrace(wnp_exception);
     361                    if (DebugStream.isDebuggingEnabled()) {
     362                        DebugStream.printStackTrace(wnp_exception);
     363                    }
    353364                    cancel_action = true;
    354365                    // Show warning
     
    632643     */
    633644    public void copyDirectoryContents(File source, File destination, LongProgressBar progress)
    634     throws FileAlreadyExistsException, FileNotFoundException, InsufficientSpaceException, IOException, UnknownFileErrorException, WriteNotPermittedException
     645    throws FileAlreadyExistsException, FileNotFoundException, InsufficientSpaceException, IOException, ReadNotPermittedException, UnknownFileErrorException, WriteNotPermittedException
    635646    {
    636647    if (!source.isDirectory()) return;
     
    659670     */
    660671    public void copyFile(File source, File destination, LongProgressBar progress)
    661     throws FileAlreadyExistsException, FileNotFoundException, InsufficientSpaceException, IOException, UnknownFileErrorException, WriteNotPermittedException {
     672    throws FileAlreadyExistsException, FileNotFoundException, InsufficientSpaceException, IOException, ReadNotPermittedException, UnknownFileErrorException, WriteNotPermittedException {
    662673    if(source.isDirectory()) {
    663674        destination.mkdirs();
     
    665676    else {
    666677        // Check if the origin file exists.
    667         if(!source.exists()) {
     678        if (!source.exists()) {
    668679        DebugStream.println("Couldn't find the source file.");
    669680        throw(new FileNotFoundException());
    670681        }
    671         // Check if the destination file does not exist.
    672         if(destination.exists()) {
     682
     683        // Make sure the destination file does not exist.
     684        if (destination.exists()) {
    673685        throw(new FileAlreadyExistsException());
    674686        }
     687
     688        // Open an input stream to the source file
     689        FileInputStream f_in = null;
     690        try {
     691        f_in = new FileInputStream(source);
     692        }
     693        catch (FileNotFoundException exception) {
     694        // A FileNotFoundException translates into a ReadNotPermittedException in this case
     695        throw new ReadNotPermittedException(exception.toString());     
     696        }
     697
     698        // Create an necessary directories for the target file
    675699        File dirs = destination.getParentFile();
    676700        dirs.mkdirs();
    677         // Copy the file.
    678         FileInputStream f_in = new FileInputStream(source);
     701
     702        // Open an output stream to the target file
    679703        FileOutputStream f_out = null;
    680         // This may throw a file not found exception, but this translates to a WriteNotPermittedException, in this case
    681704        try {
    682705        f_out = new FileOutputStream(destination);
    683706        }
    684707        catch (FileNotFoundException exception) {
     708        // A FileNotFoundException translates into a WriteNotPermittedException in this case
    685709        throw new WriteNotPermittedException(exception.toString());
    686710        }
     711
     712        // Copy the file
    687713        byte data[] = new byte[Utility.BUFFER_SIZE];
    688714        int data_size = 0;
Note: See TracChangeset for help on using the changeset viewer.