public static boolean isReadOnly(IResource resource) { ResourceAttributes resourceAttributes = resource.getResourceAttributes(); if (resourceAttributes == null) // not supported on this platform for this resource return false; return resourceAttributes.isReadOnly(); }
/** ** END Listeners *** */ protected void makeFileEditable(IFile aFile) { if (aFile == null) return; aFile.getResourceAttributes().setReadOnly(false); }
/** * Converts a ResourceAttributes object into an IFileInfo object. * @param attributes The resource attributes * @return The file info */ public static IFileInfo attributesToFileInfo(ResourceAttributes attributes) { IFileInfo fileInfo = EFS.createFileInfo(); fileInfo.setAttribute(EFS.ATTRIBUTE_READ_ONLY, attributes.isReadOnly()); fileInfo.setAttribute(EFS.ATTRIBUTE_EXECUTABLE, attributes.isExecutable()); fileInfo.setAttribute(EFS.ATTRIBUTE_ARCHIVE, attributes.isArchive()); fileInfo.setAttribute(EFS.ATTRIBUTE_HIDDEN, attributes.isHidden()); fileInfo.setAttribute(EFS.ATTRIBUTE_SYMLINK, attributes.isSymbolicLink()); fileInfo.setAttribute(EFS.ATTRIBUTE_GROUP_READ, attributes.isSet(EFS.ATTRIBUTE_GROUP_READ)); fileInfo.setAttribute(EFS.ATTRIBUTE_GROUP_WRITE, attributes.isSet(EFS.ATTRIBUTE_GROUP_WRITE)); fileInfo.setAttribute(EFS.ATTRIBUTE_GROUP_EXECUTE, attributes.isSet(EFS.ATTRIBUTE_GROUP_EXECUTE)); fileInfo.setAttribute(EFS.ATTRIBUTE_OTHER_READ, attributes.isSet(EFS.ATTRIBUTE_OTHER_READ)); fileInfo.setAttribute(EFS.ATTRIBUTE_OTHER_WRITE, attributes.isSet(EFS.ATTRIBUTE_OTHER_WRITE)); fileInfo.setAttribute(EFS.ATTRIBUTE_OTHER_EXECUTE, attributes.isSet(EFS.ATTRIBUTE_OTHER_EXECUTE)); return fileInfo; }
/** * Returns the resource attributes for this file. * * @param element * @return the attributes of the file */ public ResourceAttributes getResourceAttributes(Object element) { ResourceAttributes attributes = new ResourceAttributes(); TarEntry entry = (TarEntry) element; attributes.setExecutable((entry.getMode() & 0100) != 0); attributes.setReadOnly((entry.getMode() & 0200) == 0); return attributes; }
@Override public void performChange(IResource resource) throws CoreException { ResourceAttributes attrs = resource.getResourceAttributes(); if (attrs != null) { if (changedAttrs[0]) attrs.setReadOnly(finalAttrs[0]); if (changedAttrs[1]) attrs.setExecutable(finalAttrs[1]); if (changedAttrs[2]) attrs.setArchive(finalAttrs[2]); resource.setResourceAttributes(attrs); } } };
/** * Converts an IFileInfo object into a ResourceAttributes object. * @param fileInfo The file info * @return The resource attributes */ public static ResourceAttributes fileInfoToAttributes(IFileInfo fileInfo) { ResourceAttributes attributes = new ResourceAttributes(); attributes.setReadOnly(fileInfo.getAttribute(EFS.ATTRIBUTE_READ_ONLY)); attributes.setArchive(fileInfo.getAttribute(EFS.ATTRIBUTE_ARCHIVE)); attributes.setExecutable(fileInfo.getAttribute(EFS.ATTRIBUTE_EXECUTABLE)); attributes.setHidden(fileInfo.getAttribute(EFS.ATTRIBUTE_HIDDEN)); attributes.setSymbolicLink(fileInfo.getAttribute(EFS.ATTRIBUTE_SYMLINK)); attributes.set(EFS.ATTRIBUTE_GROUP_READ, fileInfo.getAttribute(EFS.ATTRIBUTE_GROUP_READ)); attributes.set(EFS.ATTRIBUTE_GROUP_WRITE, fileInfo.getAttribute(EFS.ATTRIBUTE_GROUP_WRITE)); attributes.set(EFS.ATTRIBUTE_GROUP_EXECUTE, fileInfo.getAttribute(EFS.ATTRIBUTE_GROUP_EXECUTE)); attributes.set(EFS.ATTRIBUTE_OTHER_READ, fileInfo.getAttribute(EFS.ATTRIBUTE_OTHER_READ)); attributes.set(EFS.ATTRIBUTE_OTHER_WRITE, fileInfo.getAttribute(EFS.ATTRIBUTE_OTHER_WRITE)); attributes.set(EFS.ATTRIBUTE_OTHER_EXECUTE, fileInfo.getAttribute(EFS.ATTRIBUTE_OTHER_EXECUTE)); return attributes; }
attrs.setReadOnly(editableBox.getSelection()); finalValues[0] = editableBox.getSelection(); changedAttrs[0] = true; attrs.setExecutable(executableBox.getSelection()); finalValues[1] = executableBox.getSelection(); changedAttrs[1] = true; attrs.setArchive(archiveBox.getSelection()); finalValues[2] = archiveBox.getSelection(); changedAttrs[2] = true; attrs = resource.getResourceAttributes(); if (attrs != null) { previousReadOnlyValue = attrs.isReadOnly(); previousExecutableValue = attrs.isExecutable(); previousArchiveValue = attrs.isArchive(); if (editableBox != null) { editableBox.setSelection(attrs.isReadOnly()); executableBox.setSelection(attrs.isExecutable()); archiveBox.setSelection(attrs.isArchive());
result.put(URIConverter.ATTRIBUTE_READ_ONLY, resourceAttributes.isReadOnly()); result.put(URIConverter.ATTRIBUTE_ARCHIVE, resourceAttributes.isArchive()); result.put(URIConverter.ATTRIBUTE_EXECUTABLE, resourceAttributes.isExecutable()); result.put(URIConverter.ATTRIBUTE_HIDDEN, resourceAttributes.isHidden());
/** * Ensure the container is not read-only. * <p> * For Linux, a Resource cannot be created in a ReadOnly folder. This is only necessary for new files. * * @param resource * workspace resource to make read/write * @since 1.0.0 */ public static void ensureContainerNotReadOnly(IResource resource) { if (resource != null && !resource.exists()) { //it must be new IContainer container = resource.getParent(); ResourceAttributes attr = container.getResourceAttributes(); while (attr != null && !attr.isReadOnly()) { container = container.getParent(); if (container == null) break; attr = container.getResourceAttributes(); } if (container != null && attr != null) attr.setReadOnly(false); } }
resourceAttributes.setReadOnly(readOnly); resourceAttributes.setArchive(archive); resourceAttributes.setExecutable(executable); resourceAttributes.setHidden(hidden);
@Override public void write(IContainer container, String destinationPath) throws IOException { if (!resolveLinks && container.isLinked(IResource.DEPTH_INFINITE)) { return; } TarEntry newEntry = new TarEntry(destinationPath); if(container.getLocalTimeStamp() != IResource.NULL_STAMP) { newEntry.setTime(container.getLocalTimeStamp() / 1000); } ResourceAttributes attributes = container.getResourceAttributes(); if (attributes != null && attributes.isExecutable()) { newEntry.setMode(newEntry.getMode() | 0111); } if (attributes != null && attributes.isReadOnly()) { newEntry.setMode(newEntry.getMode() & ~0222); } newEntry.setFileType(TarEntry.DIRECTORY); outputStream.putNextEntry(newEntry); }
ResourceAttributes attrs = resource.getResourceAttributes(); if (attrs != null) { previousReadOnlyValue = attrs.isReadOnly(); previousExecutableValue = attrs.isExecutable(); previousArchiveValue = attrs.isArchive(); } else { previousReadOnlyValue = previousExecutableValue = previousArchiveValue = false;
public void setResourceAttributes(IResource resource, ResourceAttributes attributes) throws CoreException { IFileStore store = getStore(resource); //when the executable bit is changed on a folder a refresh is required boolean refresh = false; if (resource instanceof IContainer && ((store.getFileSystem().attributes() & EFS.ATTRIBUTE_EXECUTABLE) != 0)) refresh = store.fetchInfo().getAttribute(EFS.ATTRIBUTE_EXECUTABLE) != attributes.isExecutable(); store.putInfo(FileUtil.attributesToFileInfo(attributes), EFS.SET_ATTRIBUTES, null); //must refresh in the background because we are not inside an operation if (refresh) workspace.getRefreshManager().refresh(resource); }
/** * Converts an IFileInfo object into a ResourceAttributes object. * @param fileInfo The file info * @return The resource attributes */ public static ResourceAttributes fileInfoToAttributes(IFileInfo fileInfo) { ResourceAttributes attributes = new ResourceAttributes(); attributes.setReadOnly(fileInfo.getAttribute(EFS.ATTRIBUTE_READ_ONLY)); attributes.setArchive(fileInfo.getAttribute(EFS.ATTRIBUTE_ARCHIVE)); attributes.setExecutable(fileInfo.getAttribute(EFS.ATTRIBUTE_EXECUTABLE)); attributes.setHidden(fileInfo.getAttribute(EFS.ATTRIBUTE_HIDDEN)); attributes.setSymbolicLink(fileInfo.getAttribute(EFS.ATTRIBUTE_SYMLINK)); attributes.set(EFS.ATTRIBUTE_GROUP_READ, fileInfo.getAttribute(EFS.ATTRIBUTE_GROUP_READ)); attributes.set(EFS.ATTRIBUTE_GROUP_WRITE, fileInfo.getAttribute(EFS.ATTRIBUTE_GROUP_WRITE)); attributes.set(EFS.ATTRIBUTE_GROUP_EXECUTE, fileInfo.getAttribute(EFS.ATTRIBUTE_GROUP_EXECUTE)); attributes.set(EFS.ATTRIBUTE_OTHER_READ, fileInfo.getAttribute(EFS.ATTRIBUTE_OTHER_READ)); attributes.set(EFS.ATTRIBUTE_OTHER_WRITE, fileInfo.getAttribute(EFS.ATTRIBUTE_OTHER_WRITE)); attributes.set(EFS.ATTRIBUTE_OTHER_EXECUTE, fileInfo.getAttribute(EFS.ATTRIBUTE_OTHER_EXECUTE)); return attributes; }
result.put(URIConverter.ATTRIBUTE_READ_ONLY, resourceAttributes.isReadOnly()); result.put(URIConverter.ATTRIBUTE_ARCHIVE, resourceAttributes.isArchive()); result.put(URIConverter.ATTRIBUTE_EXECUTABLE, resourceAttributes.isExecutable()); result.put(URIConverter.ATTRIBUTE_HIDDEN, resourceAttributes.isHidden());
resourceAttributes.setReadOnly(readOnly); resourceAttributes.setArchive(archive); resourceAttributes.setExecutable(executable); resourceAttributes.setHidden(hidden);
/** * Write the passed resource to the current archive. * * @param resource org.eclipse.core.resources.IFile * @param destinationPath java.lang.String * @exception java.io.IOException * @exception org.eclipse.core.runtime.CoreException */ @Override public void write(IFile resource, String destinationPath) throws IOException, CoreException { if (!resolveLinks && resource.isLinked(IResource.DEPTH_INFINITE)) { return; } TarEntry newEntry = new TarEntry(destinationPath); if(resource.getLocalTimeStamp() != IResource.NULL_STAMP) { newEntry.setTime(resource.getLocalTimeStamp() / 1000); } ResourceAttributes attributes = resource.getResourceAttributes(); if (attributes != null && attributes.isExecutable()) { newEntry.setMode(newEntry.getMode() | 0111); } if (attributes != null && attributes.isReadOnly()) { newEntry.setMode(newEntry.getMode() & ~0222); } write(newEntry, resource); } }
public void setResourceAttributes(IResource resource, ResourceAttributes attributes) throws CoreException { IFileStore store = getStore(resource); //when the executable bit is changed on a folder a refresh is required boolean refresh = false; if (resource instanceof IContainer && ((store.getFileSystem().attributes() & EFS.ATTRIBUTE_EXECUTABLE) != 0)) refresh = store.fetchInfo().getAttribute(EFS.ATTRIBUTE_EXECUTABLE) != attributes.isExecutable(); store.putInfo(FileUtil.attributesToFileInfo(attributes), EFS.SET_ATTRIBUTES, null); //must refresh in the background because we are not inside an operation if (refresh) workspace.getRefreshManager().refresh(resource); }
@Deprecated @Override public boolean isReadOnly() { final ResourceAttributes attributes = getResourceAttributes(); return attributes == null ? false : attributes.isReadOnly(); }
@Deprecated @Override public void setReadOnly(boolean readonly) { ResourceAttributes attributes = getResourceAttributes(); if (attributes == null) return; attributes.setReadOnly(readonly); try { setResourceAttributes(attributes); } catch (CoreException e) { //failure is not an option } }