Forums » User questions »
Move with overwrite
Added by Hajnal Akos almost 12 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: http://grid.in2p3.fr/software/jsaga-dev/jsaga-engine/xref/fr/in2p3/jsaga/command/NamespaceMove.html)
I do something wrong?
I tried other protocols - the same result.
Regards,
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://192.168.153.100/tmp/x.txt"); 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="}); session.addContext(ctx); 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\jsaga-config.properties (The system cannot find the path specified)] BadParameter: Flags not allowed for this method: 1 at fr.in2p3.jsaga.impl.namespace.FlagsHelper.allowed(FlagsHelper.java:39) at fr.in2p3.jsaga.impl.namespace.FlagsHelper.allowed(FlagsHelper.java:27) at fr.in2p3.jsaga.impl.namespace.AbstractSyncNSEntryImpl.removeSync(AbstractSyncNSEntryImpl.java:278) at fr.in2p3.jsaga.impl.file.AbstractSyncFileImpl.removeSync(AbstractSyncFileImpl.java:170) at fr.in2p3.jsaga.impl.namespace.AbstractSyncNSEntryImpl.moveSync(AbstractSyncNSEntryImpl.java:269) at fr.in2p3.jsaga.impl.namespace.AbstractNSEntryImpl.move(AbstractNSEntryImpl.java:254) at fr.in2p3.jsaga.impl.file.AbstractNSEntryImplWithStream.move(AbstractNSEntryImplWithStream.java:105) at Move.main(Move.java:19)
Replies (4)
RE: Move with overwrite
-
Added by Schwarz Lionel almost 12 years ago
This is a bug:
https://forge.in2p3.fr/issues/4695
RE: Move with overwrite
-
Added by Hajnal Akos almost 12 years ago
Move with overwrite works fine in the new release. Thanks!
Akos
RE: Move with overwrite
-
Added by Hajnal Akos almost 12 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).
Regards,
Akos
RE: Move with overwrite
-
Added by Schwarz Lionel almost 12 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 https://forge.in2p3.fr/issues/4695
Lionel