Skip to main content



      Home
Home » Newcomers » Newcomers » Is "chmod +x ..." equiv. to IFileInfo.setAttribute(EFS.ATTRIBUTE_EXECUTABLE, ...)?
Is "chmod +x ..." equiv. to IFileInfo.setAttribute(EFS.ATTRIBUTE_EXECUTABLE, ...)? [message #151766] Thu, 11 May 2006 16:36 Go to next message
Eclipse UserFriend
Someone suggested me to ask this group
to find what's the Eclipse way of doing
the unix equivalent of "chmod +x <file>" in Java?

From my understanding of the Eclipse file system APIs,
I believed the code sketch below should work.

import org.eclipse.core.filesystem.EFS;
import org.eclipse.core.filesystem.IFileInfo;
import org.eclipse.core.filesystem.IFileStore;

Bundle bundle = ...; // a plugin bundle
String path = "/some-script.sh";
URL url = bundle.getEntry(path);
URI uri = URIUtil.toURI(url.getFile);
IFileStore store = EFS.getStore(uri);
IFileInfo info = store.fetchInfo();
if (!info.getAttribute(EFS.ATTRIBUTE_EXECUTABLE)) {
System.out.println(" -x => +x");
info.setAttribute(EFS.ATTRIBUTE_EXECUTABLE, true);
store.putInfo(info, EFS.SET_ATTRIBUTES, null);
} else {
System.out.println(" +x is set!");
}

I implemented this and when I manually do chmod -x some-script.sh;
I can see the message: -x => +x
but the file doesn't get the x flag set.

When I manually do chmod +x some-script.sh;
I can see the message: +x is set!

So, the IFileInfo.getAttribute(...) part is OK;
however, it seems that
the IFileInfo.setAttribute + IFileStore.putInfo part is not OK.

I searched for references to these methods and I haven't found
evidence of anything in Eclipse that specifically uses the file system
API to do the equivalent of "chmod +x ...".

Any suggestions for alternative workarounds known to work as expected?

-- Nicolas.
Re: Is "chmod +x ..." equiv. to IFileInfo.setAttribute(EFS.ATTRIBUTE_EXECUTABLE, ...)? [message #152261 is a reply to message #151766] Fri, 12 May 2006 13:12 Go to previous message
Eclipse UserFriend
Originally posted by: jefmyers.us.ibm.com

Nicolas,

Reading your post I became curious how this stuff works. I dug around a
bit and found that it looks to me like your code should work. To answer
your question about where the chmod actually occurs - it happens in a
native library within the OS-specific native code fragment of
org.eclipse.core.filesystem.<platform>. The source of this native code
for unix systems is here:
http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.core.fi lesystem/natives/unix/localfile.c?rev=1.4&content-type=t ext/vnd.viewcvs-markup
Look for the JNI internalSetFileInfo method. The Java side of this JNI
library is LocalFileNatives, which is called by LocalFile, which should
be called by your code's putInfo()

I'm not sure why it's not working for you. One thing I can suggest is
selecting a file in the Navigator view, right clicking and select
Properties. The Executable checkbox should show up on the Info page on
Unix systems. Try checking the box, hitting OK, and then looking at the
file on the filesystem to see if the change happened. If it doesn't,
I'd open a bug.

One other possibility is that this function may only work on files
within the workspace, and not on arbitrary files on the file system, but
looking through the code I don't see any checks to this effect. You
might want to check the runtime workbench's .log file to see if any
errors are being logged.

Hope this helps,
- Jeff
Previous Topic:pde related stuff
Next Topic:Package?
Goto Forum:
  


Current Time: Wed Jul 02 20:40:46 EDT 2025

Powered by FUDForum. Page generated in 0.05195 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top