Community
Participate
Working Groups
Reported for Eclipse integration build 20020108. I thing the Eclipse must protect read-only files from editing (not only when saving, in editor too). Now there is this problem which is critical for us: 1) setting test.java attribute read-only 2) starting Eclipse with workspace linked to file test.java 3) opening Eclipse editor with test.java 4) making changes in this editor 5) trying save (by toolbar icon save) 6) dialog "Save could not be completed. Reason: Core exception: Could not write to read-only file: /markus1/src/markus/test1/Test.java", submited by button OK and not saving file. 7) close Eclipse editor 8) open Eclipse editor again and editor shows changed code in 4)! 9) close Eclipse editor 10) file on disk is old, but in some Eclipse cache is changed 11) setting test.java attribute read-only to false 12) editing test.java with external editor (or may be check out from SourceSafe) 13) open Eclipse editor and editor shows changed code in 4), not from 12)! 14) closing Eclipse editor 15) using right mouse button on test.java file in packages window - item Refresh from local 16) open Eclipse editor and editor still shows changed code in 4), not from 12)! 17) closing Eclipse 18) starting Eclipse 19) open Eclipse editor and editor now shows changed code from 12)! Its very dangerous for us bcause we are working with SourceSafe and checking files (copying, protecting files by read-only attributes) very offen.
One possibility for this behaviour is that the file is open in another perspective. To verify this case you can use Window->Switch to Editor. If the editor shows up two or more times, you will get the described behaviour. Need to investigate in a better handling of read only files in this case.
Comments provided by Milan Fort (Milan.Fort@bsc.cz) I read your comment and investigated that I have only one perspective with editor. When I open read-only file, I can edit it and than close by X. In dialog I say "No save changes" and everything is ok, when I open file again, its still original (from time before I changed it). But When I open read-only file, editing it and than close by X and dialog I say "Save changes", than i get error message "Save could not be completed. Reason: Core exception: Could not write to read-only file: ..." AND when I open file again, its changed! When i now change attribute of file to writtable, I can save data from editor to file and replace original file on disk.
Only the Java editor exhibits this behavior. It's not shown by the default text editor. So it seems that it's a Java model issue. Suspect offending code in CommitWorkingCopyOperation.executeOperation: original.getBuffer().setContents(copy.getBuffer().getCharacters()); original.save(fMonitor, fForce); The save call should be surrounded by a finally clause resetting the original's buffer.
I think that there are two problems: 1) when saving fails, the state is inconsistent since what eclipse thinks is the current state is not what is reflected on the hardisk 2) the editor does not prevent you from editing read-only files While problem 1) is rather subtle, problem 2) should be easier to tackle and would also help avoiding most of the problems described here. I also think that it is annoying if you're working with a VCS that treats non- checked-out files as read-only (like clearcase snapshot views do).
Only the in-memory buffer got corrupted, and needs to be corrected in case an exception occurred while setting the buffer. Also added a pre-check in operation verify() code so as to recognize this scenario upfront.
Removed the precheck in #verify() since ClearCase repo does change the read only flag on save request.