Move with overwrite

Added by Hajnal Akos almost 6 years ago

Dear Developers,

I have a minor (but annoying) problem: I cannot move files with the OVERWRITE flag.
(This option is supported in the example:

I do something wrong?
I tried other protocols - the same result.

Akos Hajnal

The code:

import org.ogf.saga.context.*;
import org.ogf.saga.namespace.*;
import org.ogf.saga.session.*;
import org.ogf.saga.url.*;

public class Move {
    public static void main(String[] args) {
        NSEntry file = null;
        try {
            URL fromUrl = URLFactory.createURL("sftp://");
            Session session = SessionFactory.createSession(false);
            Context ctx = ContextFactory.createContext("UserPass"); 
            ctx.setAttribute(Context.USERID, "user");
            ctx.setAttribute(Context.USERPASS, "***");
            ctx.setVectorAttribute("DataServiceAttributes", new String[]{"sftp.KnownHosts="}); 
            URL toUrl = URLFactory.createURL("file://d:/Trash/x.txt");  
            file = NSFactory.createNSEntry(session, fromUrl);
            file.move(toUrl, Flags.OVERWRITE.getValue());
        } catch(Exception x) { x.printStackTrace(); }
        finally { try { file.close(); } catch (Exception e) {} }

The exception:

[main] WARN  impl.SagaFactoryImpl  - Failed to load engine properties, using defaults [.\etc\ (The system cannot find the path specified)]
BadParameter: Flags not allowed for this method: 1
    at fr.in2p3.jsaga.impl.namespace.FlagsHelper.allowed(
    at fr.in2p3.jsaga.impl.namespace.FlagsHelper.allowed(
    at fr.in2p3.jsaga.impl.namespace.AbstractSyncNSEntryImpl.removeSync(
    at fr.in2p3.jsaga.impl.file.AbstractSyncFileImpl.removeSync(
    at fr.in2p3.jsaga.impl.namespace.AbstractSyncNSEntryImpl.moveSync(
    at fr.in2p3.jsaga.impl.namespace.AbstractNSEntryImpl.move(
    at fr.in2p3.jsaga.impl.file.AbstractNSEntryImplWithStream.move(
    at Move.main(

Replies (4)

RE: Move with overwrite - Added by Hajnal Akos almost 6 years ago

Move with overwrite works fine in the new release. Thanks!


RE: Move with overwrite - Added by Hajnal Akos almost 6 years ago

Sorry, but one more problem that belongs to this topic.

I tried to move entire directories with the OVERWRITE flag:

entry = NSFactory.createNSDirectory(session, sourceDir, Flags.NONE.getValue());
entry.move(TaskMode.TASK, targetDir, Flags.OVERWRITE.or(Flags.RECURSIVE.getValue()));

I got a "Flags not allowed for this method: 1" failure cause for the OVERWRITE flag (with task status: FAILED).

What is strange that files are actually moved from source dir to target location correctly (in spite of the failure message),
but source directories remained at the source location (without files inside that are moved successfuly).


RE: Move with overwrite - Added by Schwarz Lionel almost 6 years ago

Hi Akos,
I can explain this:
If the data adaptor does not support rename(), then move()=copy()+delete(). Before my previous fix, flags were passed to copy() and then passed to delete(). The problem was that delete() does not support OVERWRITE.
It seems I have fixed the bug for files but not for directories, that's why files are moved and then there is an exception at the end of the process when JSAGA tries to do the directory.delete() with OVERWRITE flag.

I have updated the ticket