You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Emanuele Ianni <di...@gmail.com> on 2012/09/24 11:09:00 UTC

[VFS2] I can't delete a file with VFS2 if it's pointed by two variables

This is the code:

    FileObject localRecipients = null;
    FileObject localRecipientsCsv = null;

    try {
        if (dto.getCsvFile() != null) {

        // file sul server remote csv o zip
        FileObject remoteRecipientsFile = manager.resolveFile(
            semaphoreFile.getParent(), dto.getCsvFile());

        // carico nel localRecipients il file specificando un nuovo
        // nome
        localRecipients = manager.resolveFile(Functions
            .buildLocalRecipientsfilename(configurationHeader,
                remoteRecipientsFile));

        localRecipients.copyFrom(remoteRecipientsFile,
            Selectors.SELECT_SELF);

        // controllo se รจ presente l'estensione zip sul file remoto.
        if (remoteRecipientsFile.getName().getExtension()
            .equalsIgnoreCase(Constants.EXTENSION_ZIP.getValue())) {

        // this builds something like zip:// arch-file-uri[! absolute-path]
            FileObject localRecipientsZip = manager
                .resolveFile(Functions
                    .buildCompressedFileRoot(localRecipients));

            localRecipientsCsv = VFS.getManager().resolveFile(
                localRecipients.getParent(),
                localRecipients
                    .getName()
                    .getBaseName()
                    .substring(
                        0,
                        localRecipients.getName()
                            .getBaseName().length()
                            - Constants.EXTENSION_ZIP
                                .getValue()
                                .length() - 1));
            localRecipientsCsv.copyFrom(
                localRecipientsZip.getChildren()[0],
                Selectors.SELECT_SELF);

            localRecipientsZip.close();
            remoteRecipientsFile.close();
            remoteRecipientsFile = null;
            localRecipientsZip = null;
        } else {
            localRecipientsCsv = localRecipients;
        }

    /*   */

        } else if (dto.isXMLRecipients()) {
        /* */

        }
    } catch (FileSystemException e) {
        /***/
    }

    try {
        notifyObservers(new XMLDLoggerTrigger(
            DeliveryStatusType.RECIPIENTS_UPLOAD_STARTED, new Object[] {
                this.id, new Date(),
                localRecipients.getName().getBaseName() }));

        reader.attach(this);
        reader.load();

    } catch (IOException e) {
        /* */
    } finally {
        try {
        notifyObservers(new XMLDLoggerTrigger(
            DeliveryStatusType.RECIPIENTS_UPLOAD_FINISHED,
            new Object[] { this.id, new Date(), recipientsCount }));

        if (localRecipientsCsv != null) {
            localRecipientsCsv.delete();
            localRecipientsCsv.close();
            localRecipientsCsv = null;
        }

        if (localRecipients != null) {
            localRecipients.getContent().close();
            // ERROR
            localRecipients.delete();
            localRecipients.close();
            localRecipients = null;
        }

        } catch (FileSystemException e) {
        saveStep(DeliveryStatusType.GENERIC_ERROR,
            "xmld2.systemlogger.error.filesystemexception", e);
        }
    }

    /*  */

}

The problem is localRecipients.delete(); where I have an error about it's
not possible to delete a file. And I also can't delete it from the
filebrowser because someone is reading it. The problem is happening when I
go inside the
if (remoteRecipientsFile.getName().getExtension()
.equalsIgnoreCase(Constants.EXTENSION_ZIP.getValue())) {

branch because localRecipients and localRecipientsZip are pointing to the
same file. But I close localRecipientsZip.

It's something stupid but I can't see it.

-- 
Distinti Saluti
Emanuele Ianni

Le informazioni e gli allegati contenuti in questa e-mail sono considerati
confidenziali e possono essere riservati. Qualora non foste il
destinatario, siete pregati di distruggere questo messaggio e notificarmi
il problema immediatamente. In ogni caso, non dovrete spedire a terze parti
questa e-mail. Vi ricordo che la diffusione, l'utilizzo e/o la
conservazione dei dati ricevuti per errore costituiscono violazione alle
disposizioni del D.L. n. 196/2003 denominato "Codice in materia di
protezione dei dati personali"
Tale disclaimer non vale nel caso il messaggio sia in una mailing list
pubblica.

The information in this e.mail and in any attachements is confidential and
may be privileged. If you are not the intended recipient, please destroy
this message and notify the sender immediately. You should not retain, copy
or use this e.mail for any purpose, nor disclose all or any part of its
contents to any other person according to the Italian Legislative Decree n.
196/2003.
This disclaimer should be not considered if the message is on a public
mailing list.