Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 323946

Summary: Copied resources have user only access rights (-rw-------) instead of group (-rw-rw-r--) like classes
Product: [Eclipse Project] Platform Reporter: Laurent Chaply <chaply>
Component: ResourcesAssignee: Szymon Brandys <Szymon.Brandys>
Status: RESOLVED DUPLICATE QA Contact:
Severity: major    
Priority: P3 CC: jamesblackburn+eclipse, Olivier_Thomann, ppdkseth222, richardfearn, sptaszkiewicz, Szymon.Brandys
Version: 3.7   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Whiteboard:
Attachments:
Description Flags
Proposed fix for this bug none

Description Laurent Chaply CLA 2010-08-30 05:52:48 EDT
Build Identifier: 20100617-1415

Linux distro: Fedora 12 x64
JDK 1.6.0_18 x64

I'm running eclipse as a standard user
When resources are copied from source directory to target directory, the access rights are changed as described in the subject.
When I run an application server with a different user which points to this target directory, I have an expected MissingResourcesException.
It's only resources, classes are generated with the correct access rights -rw-rw-r--

With previous version of Eclipse (Galileo 20090920-1017) on the same workspace, resources are copied with -rw-rw-r-- rights like classes.

Laurent


Reproducible: Always

Steps to Reproduce:
1. Run Eclipse as a standard user
2. Simply build a Java project with resources in it.
Comment 1 Olivier Thomann CLA 2010-09-03 09:06:06 EDT
The builder is using:
org.eclipse.core.resources.IResource.copy(IPath, int, IProgressMonitor)
to copy resources.

So the problem might come from the underlying resource layer.
Moving to Platform/Resources for comment.

Note that I could not reproduce myself as I don't have access to a Linux box right now.
Comment 2 Szymon Brandys CLA 2010-09-03 09:36:36 EDT
(In reply to comment #0)

When a build is performed, Java files from the source directory are built and appropriate class files are created in the target directory. For newly created files Umask is used to set the attributes. I guess that Umask on your machine is -rw-rw-r--. 

What do you mean by 'resources are copied from source directory to target directory'? Do you copy them manually?

And how do you create files in your source directory. Can you explain that?
Comment 3 John Arthorne CLA 2010-09-03 13:49:12 EDT
(In reply to comment #2)
> What do you mean by 'resources are copied from source directory to target
> directory'? Do you copy them manually?

The Java builder copies all non ".java" resources directly from the source to the target directory. As Olivier says they just use the IResource API to perform that copying.
Comment 4 Szymon Brandys CLA 2010-09-06 04:26:17 EDT
(In reply to comment #3)
> The Java builder copies all non ".java" resources directly from the source to
> the target directory. As Olivier says they just use the IResource API to
> perform that copying.

Thanks John. It was not clear for me from the Olivier's comment.

Laurent, could you explain how you create files in your source directory? Do you change their access rights before the build is performed?
Comment 5 Laurent Chaply CLA 2010-09-06 05:22:39 EDT
Hi,

I did the test again:

Fresh install of eclipse helios (unpacked from eclipse.org jar as root in /opt/eclipse/helios, and ran with standard user "laurent")
Fresh workspace in /home/laurent/workspace
New -> Java project TestProject
In src, new -> file test.properties

It's copied automatically in bin which is the default target directory.

ls -al /home/laurent/workspace/TestProject/bin/test.properties
-rw------- 1 laurent laurent 0 2010-09-06 10:48 /home/laurent/workspace/TestProject/bin/test.properties

Exact same test with Galileo (installed the same way as helios: unpacked from eclipse.org jar as root in /opt/eclipse/galileo, and ran with same standard user "laurent")
in a new fresh workspace workspace2

ls -al /home/laurent/workspace2/TestProject/bin/test.properties
-rw-rw-r-- 1 laurent laurent 0 2010-09-06 10:56 /home/laurent/workspace2/TestProject/bin/test.properties

Regards,

Laurent

(In reply to comment #4)
> (In reply to comment #3)
> > The Java builder copies all non ".java" resources directly from the source to
> > the target directory. As Olivier says they just use the IResource API to
> > perform that copying.
> 
> Thanks John. It was not clear for me from the Olivier's comment.
> 
> Laurent, could you explain how you create files in your source directory? Do
> you change their access rights before the build is performed?
Comment 6 ppdkseth222 CLA 2011-02-01 07:23:44 EST
I reproduced this on:

- Linux 2.6.31-14-generic #48-Ubuntu SMP Fri Oct 16 14:04:26 UTC 2009 i686 GNU/Linux
Distributor ID:	Ubuntu
Description:	Ubuntu 9.10
Release:	9.10
Codename:	karmic

- Helios Service Release 1,
according to About box, Build id=20100917-0705,
according to Configuration Details->Configuration, eclipse.buildId=M20100909-0800

- java version "1.6.0_20"
Java(TM) SE Runtime Environment (build 1.6.0_20-b02)
Oracle JRockit(R) (build R28.0.1-21-133393-1.6.0_20-20100512-2126-linux-ia32, compiled mode)

- libgtk 2.18.3-1ubuntu2.2  

- umask 0022

It seems that this issue applies only to files (resources, not source files) that are automatically copied to the output directory as part of the build process. If i manually copy a file through the Navigator, using Copy & Paste, the destination's permissions are right (i.e. same as the source).
Comment 7 ppdkseth222 CLA 2011-02-08 09:48:09 EST
Created attachment 188520 [details]
Proposed fix for this bug

I traced the problem into JDT's AbstractImageBuilder and specifically into this method:

protected void copyResource(IResource source, IResource destination) throws CoreException {
	IPath destPath = destination.getFullPath();
	try {
		source.copy(destPath, IResource.FORCE | IResource.DERIVED, null);
	} catch (CoreException e) {
		// handle the case when the source resource is deleted
		source.refreshLocal(0, null);
		if (!source.exists()) return; // source resource was deleted so skip it
		throw e;
	}
	Util.setReadOnly(destination, false); // just in case the original was read only
}

What happens is that after copying the file (including its filesystem attributes), for some unknown reason ("just in case the original was read only") we overwrite them by using Util.setReadOnly(..)

I attached a patch/fix, i believe it's appropriate.
Comment 8 Szymon Brandys CLA 2011-03-23 10:23:45 EDT
.

*** This bug has been marked as a duplicate of bug 323681 ***