Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 186381 Details for
Bug 332543
IFile#setContents eats I/O Exception on close => potential file corruption
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
patch 2
bug332543.patch (text/plain), 44.48 KB, created by
James Blackburn
on 2011-01-10 07:24:31 EST
(
hide
)
Description:
patch 2
Filename:
MIME Type:
Creator:
James Blackburn
Created:
2011-01-10 07:24:31 EST
Size:
44.48 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.core.filesystem >Index: src/org/eclipse/core/filesystem/provider/FileStore.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.core.filesystem/src/org/eclipse/core/filesystem/provider/FileStore.java,v >retrieving revision 1.30 >diff -u -r1.30 FileStore.java >--- src/org/eclipse/core/filesystem/provider/FileStore.java 17 Nov 2008 18:21:58 -0000 1.30 >+++ src/org/eclipse/core/filesystem/provider/FileStore.java 10 Jan 2011 12:21:32 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2005, 2008 IBM Corporation and others. >+ * Copyright (c) 2005, 2011 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -7,6 +7,7 @@ > * > * Contributors: > * IBM Corporation - initial API and implementation >+ * James Blackburn (Broadcom Corp.) - ongoing development > *******************************************************************************/ > package org.eclipse.core.filesystem.provider; > >@@ -76,9 +77,11 @@ > String msg = NLS.bind(Messages.failedReadDuringWrite, path); > Policy.error(EFS.ERROR_READ, msg, e); > } >- if (bytesRead == -1) >- break; > try { >+ if (bytesRead == -1) { >+ destination.close(); >+ break; >+ } > destination.write(buffer, 0, bytesRead); > } catch (IOException e) { > String msg = NLS.bind(Messages.couldNotWrite, path); >#P org.eclipse.core.resources >Index: src/org/eclipse/core/internal/localstore/Bucket.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.core.resources/src/org/eclipse/core/internal/localstore/Bucket.java,v >retrieving revision 1.19 >diff -u -r1.19 Bucket.java >--- src/org/eclipse/core/internal/localstore/Bucket.java 20 Dec 2010 22:16:00 -0000 1.19 >+++ src/org/eclipse/core/internal/localstore/Bucket.java 10 Jan 2011 12:21:32 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2004, 2009 IBM Corporation and others. >+ * Copyright (c) 2004, 2011 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -7,6 +7,7 @@ > * > * Contributors: > * IBM Corporation - initial API and implementation >+ * James Blackburn (Broadcom Corp.) - ongoing development > *******************************************************************************/ > package org.eclipse.core.internal.localstore; > >@@ -14,6 +15,7 @@ > import java.util.*; > import org.eclipse.core.internal.resources.ResourceException; > import org.eclipse.core.internal.resources.ResourceStatus; >+import org.eclipse.core.internal.utils.FileUtil; > import org.eclipse.core.internal.utils.Messages; > import org.eclipse.core.resources.IResourceStatus; > import org.eclipse.core.runtime.*; >@@ -350,8 +352,9 @@ > writeEntryKey(destination, entry.getKey()); > writeEntryValue(destination, entry.getValue()); > } >- } finally { > destination.close(); >+ } finally { >+ FileUtil.safeClose(destination); > } > needSaving = false; > } catch (IOException ioe) { >Index: src/org/eclipse/core/internal/localstore/BucketTree.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.core.resources/src/org/eclipse/core/internal/localstore/BucketTree.java,v >retrieving revision 1.12 >diff -u -r1.12 BucketTree.java >--- src/org/eclipse/core/internal/localstore/BucketTree.java 3 Jun 2008 12:34:51 -0000 1.12 >+++ src/org/eclipse/core/internal/localstore/BucketTree.java 10 Jan 2011 12:21:32 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2004, 2008 IBM Corporation and others. >+ * Copyright (c) 2004, 2011 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -7,6 +7,7 @@ > * > * Contributors: > * IBM Corporation - initial API and implementation >+ * James Blackburn (Broadcom Corp.) - ongoing development > *******************************************************************************/ > package org.eclipse.core.internal.localstore; > >@@ -14,6 +15,7 @@ > import org.eclipse.core.internal.localstore.Bucket.Visitor; > import org.eclipse.core.internal.resources.ResourceException; > import org.eclipse.core.internal.resources.Workspace; >+import org.eclipse.core.internal.utils.FileUtil; > import org.eclipse.core.internal.utils.Messages; > import org.eclipse.core.resources.*; > import org.eclipse.core.runtime.*; >@@ -139,24 +141,15 @@ > if (!versionFile.getParentFile().exists()) > versionFile.getParentFile().mkdirs(); > FileOutputStream stream = null; >- boolean failed = false; > try { > stream = new FileOutputStream(versionFile); > stream.write(current.getVersion()); >+ stream.close(); > } catch (IOException e) { >- failed = true; > String message = NLS.bind(Messages.resources_writeWorkspaceMeta, versionFile.getAbsolutePath()); > throw new ResourceException(IResourceStatus.FAILED_WRITE_METADATA, null, message, e); > } finally { >- try { >- if (stream != null) >- stream.close(); >- } catch (IOException e) { >- if (!failed) { >- String message = NLS.bind(Messages.resources_writeWorkspaceMeta, versionFile.getAbsolutePath()); >- throw new ResourceException(IResourceStatus.FAILED_WRITE_METADATA, null, message, e); >- } >- } >+ FileUtil.safeClose(stream); > } > } > >Index: src/org/eclipse/core/internal/localstore/FileSystemResourceManager.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.core.resources/src/org/eclipse/core/internal/localstore/FileSystemResourceManager.java,v >retrieving revision 1.129 >diff -u -r1.129 FileSystemResourceManager.java >--- src/org/eclipse/core/internal/localstore/FileSystemResourceManager.java 20 Dec 2010 22:16:00 -0000 1.129 >+++ src/org/eclipse/core/internal/localstore/FileSystemResourceManager.java 10 Jan 2011 12:21:33 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2010 IBM Corporation and others. >+ * Copyright (c) 2000, 2011 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -9,6 +9,7 @@ > * IBM Corporation - initial API and implementation > * Martin Oberhuber (Wind River) - [210664] descriptionChanged(): ignore LF style > * Martin Oberhuber (Wind River) - [233939] findFilesForLocation() with symlinks >+ * James Blackburn (Broadcom Corp.) - ongoing development > *******************************************************************************/ > package org.eclipse.core.internal.localstore; > >@@ -1091,17 +1092,12 @@ > try { > out = fileStore.openOutputStream(EFS.NONE, null); > new ModelObjectWriter().write(desc, out); >+ out.close(); > } catch (IOException e) { > String msg = NLS.bind(Messages.resources_writeMeta, target.getFullPath()); > throw new ResourceException(IResourceStatus.FAILED_WRITE_METADATA, target.getFullPath(), msg, e); > } finally { >- if (out != null) { >- try { >- out.close(); >- } catch (IOException e) { >- // ignore failure to close stream >- } >- } >+ FileUtil.safeClose(out); > } > //for backwards compatibility, ensure the old .prj file is deleted > getWorkspace().getMetaArea().clearOldDescription(target); >Index: src/org/eclipse/core/internal/localstore/SafeChunkyOutputStream.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.core.resources/src/org/eclipse/core/internal/localstore/SafeChunkyOutputStream.java,v >retrieving revision 1.9 >diff -u -r1.9 SafeChunkyOutputStream.java >--- src/org/eclipse/core/internal/localstore/SafeChunkyOutputStream.java 4 Apr 2006 20:53:47 -0000 1.9 >+++ src/org/eclipse/core/internal/localstore/SafeChunkyOutputStream.java 10 Jan 2011 12:21:33 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2005 IBM Corporation and others. >+ * Copyright (c) 2000, 2011 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -7,10 +7,12 @@ > * > * Contributors: > * IBM Corporation - initial API and implementation >+ * James Blackburn (Broadcom Corp.) - ongoing development > *******************************************************************************/ > package org.eclipse.core.internal.localstore; > > import java.io.*; >+import org.eclipse.core.internal.utils.FileUtil; > > /** > * Appends data, in chunks, to a file. Each chunk is defined by the moment >@@ -63,9 +65,10 @@ > public void succeed() throws IOException { > try { > endChunk(); >+ close(); > } finally { > isOpen = false; >- close(); >+ FileUtil.safeClose(this); > } > } > >Index: src/org/eclipse/core/internal/localstore/SafeFileOutputStream.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.core.resources/src/org/eclipse/core/internal/localstore/SafeFileOutputStream.java,v >retrieving revision 1.17 >diff -u -r1.17 SafeFileOutputStream.java >--- src/org/eclipse/core/internal/localstore/SafeFileOutputStream.java 3 Jun 2008 12:34:51 -0000 1.17 >+++ src/org/eclipse/core/internal/localstore/SafeFileOutputStream.java 10 Jan 2011 12:21:33 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2006 IBM Corporation and others. >+ * Copyright (c) 2000, 2011 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -7,6 +7,7 @@ > * > * Contributors: > * IBM Corporation - initial API and implementation >+ * James Blackburn (Broadcom Corp.) - ongoing development > *******************************************************************************/ > package org.eclipse.core.internal.localstore; > >@@ -86,6 +87,7 @@ > source = new BufferedInputStream(new FileInputStream(sourceFile)); > destination = new BufferedOutputStream(new FileOutputStream(destinationFile)); > transferStreams(source, destination); >+ destination.close(); > } finally { > FileUtil.safeClose(source); > FileUtil.safeClose(destination); >Index: src/org/eclipse/core/internal/resources/FileState.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/FileState.java,v >retrieving revision 1.27 >diff -u -r1.27 FileState.java >--- src/org/eclipse/core/internal/resources/FileState.java 3 Jun 2008 12:34:50 -0000 1.27 >+++ src/org/eclipse/core/internal/resources/FileState.java 10 Jan 2011 12:21:33 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2007 IBM Corporation and others. >+ * Copyright (c) 2000, 2011 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -7,13 +7,13 @@ > * > * Contributors: > * IBM Corporation - initial API and implementation >+ * James Blackburn (Broadcom Corp.) - ongoing development > *******************************************************************************/ > package org.eclipse.core.internal.resources; > > import java.io.*; > import org.eclipse.core.internal.localstore.IHistoryStore; >-import org.eclipse.core.internal.utils.Messages; >-import org.eclipse.core.internal.utils.UniversalUniqueIdentifier; >+import org.eclipse.core.internal.utils.*; > import org.eclipse.core.resources.*; > import org.eclipse.core.runtime.*; > import org.eclipse.core.runtime.content.IContentDescription; >@@ -53,23 +53,15 @@ > // tries to obtain a description for the file contents > IContentTypeManager contentTypeManager = Platform.getContentTypeManager(); > InputStream contents = new BufferedInputStream(getContents()); >- boolean failed = false; > try { > IContentDescription description = contentTypeManager.getDescriptionFor(contents, getName(), new QualifiedName[] {IContentDescription.CHARSET}); >+ contents.close(); > return description == null ? null : description.getCharset(); > } catch (IOException e) { >- failed = true; > String message = NLS.bind(Messages.history_errorContentDescription, getFullPath()); > throw new ResourceException(IResourceStatus.FAILED_DESCRIBING_CONTENTS, getFullPath(), message, e); > } finally { >- try { >- contents.close(); >- } catch (IOException e) { >- if (!failed) { >- String message = NLS.bind(Messages.history_errorContentDescription, getFullPath()); >- throw new ResourceException(IResourceStatus.FAILED_DESCRIBING_CONTENTS, getFullPath(), message, e); >- } >- } >+ FileUtil.safeClose(contents); > } > } > >Index: src/org/eclipse/core/internal/resources/LocalMetaArea.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/LocalMetaArea.java,v >retrieving revision 1.46 >diff -u -r1.46 LocalMetaArea.java >--- src/org/eclipse/core/internal/resources/LocalMetaArea.java 29 Nov 2010 12:10:40 -0000 1.46 >+++ src/org/eclipse/core/internal/resources/LocalMetaArea.java 10 Jan 2011 12:21:33 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2010 IBM Corporation and others. >+ * Copyright (c) 2000, 2011 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -8,7 +8,7 @@ > * Contributors: > * IBM Corporation - initial API and implementation > * Francis Lynch (Wind River) - [301563] Save and load tree snapshots >- * Broadcom Corporation - build configurations and references >+ * Broadcom Corporation - ongoing development > *******************************************************************************/ > package org.eclipse.core.internal.resources; > >@@ -19,8 +19,7 @@ > import org.eclipse.core.filesystem.URIUtil; > import org.eclipse.core.internal.localstore.SafeChunkyInputStream; > import org.eclipse.core.internal.localstore.SafeChunkyOutputStream; >-import org.eclipse.core.internal.utils.Messages; >-import org.eclipse.core.internal.utils.Policy; >+import org.eclipse.core.internal.utils.*; > import org.eclipse.core.resources.*; > import org.eclipse.core.runtime.*; > import org.eclipse.osgi.util.NLS; >@@ -480,8 +479,9 @@ > } > } > output.succeed(); >- } finally { > dataOut.close(); >+ } finally { >+ FileUtil.safeClose(dataOut); > } > } catch (IOException e) { > String message = NLS.bind(Messages.resources_exSaveProjectLocation, target.getName()); >Index: src/org/eclipse/core/internal/resources/ModelObjectWriter.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/ModelObjectWriter.java,v >retrieving revision 1.37 >diff -u -r1.37 ModelObjectWriter.java >--- src/org/eclipse/core/internal/resources/ModelObjectWriter.java 25 Apr 2010 23:15:36 -0000 1.37 >+++ src/org/eclipse/core/internal/resources/ModelObjectWriter.java 10 Jan 2011 12:21:33 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2010 IBM Corporation and others. >+ * Copyright (c) 2000, 2011 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -10,6 +10,7 @@ > * Serge Beauchamp (Freescale Semiconductor) - [252996] add resource filtering > * Serge Beauchamp (Freescale Semiconductor) - [229633] Group and Project Path Variable Support > * Markus Schorn (Wind River) - [306575] Save snapshot location with project >+ * James Blackburn (Broadcom Corp.) - ongoing development > *******************************************************************************/ > package org.eclipse.core.internal.resources; > >@@ -155,9 +156,9 @@ > try { > file = new SafeFileOutputStream(location.toOSString(), tempPath); > write(object, file); >+ file.close(); > } finally { >- if (file != null) >- file.close(); >+ FileUtil.safeClose(file); > } > } > >@@ -170,8 +171,10 @@ > write(object, writer); > writer.flush(); > writer.close(); >+ if (writer.checkError()) >+ throw new IOException(); > } finally { >- output.close(); >+ FileUtil.safeClose(output); > } > } > >Index: src/org/eclipse/core/internal/resources/ProjectDescriptionReader.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/ProjectDescriptionReader.java,v >retrieving revision 1.44 >diff -u -r1.44 ProjectDescriptionReader.java >--- src/org/eclipse/core/internal/resources/ProjectDescriptionReader.java 25 Apr 2010 23:15:36 -0000 1.44 >+++ src/org/eclipse/core/internal/resources/ProjectDescriptionReader.java 10 Jan 2011 12:21:33 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2010 IBM Corporation and others. >+ * Copyright (c) 2000, 2011 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -9,6 +9,7 @@ > * IBM Corporation - initial API and implementation > * Serge Beauchamp (Freescale Semiconductor) - [229633] Project Path Variable Support > * Markus Schorn (Wind River) - [306575] Save snapshot location with project >+ * James Blackburn (Broadcom Corp.) - ongoing development > *******************************************************************************/ > package org.eclipse.core.internal.resources; > >@@ -20,8 +21,7 @@ > import org.eclipse.core.filesystem.URIUtil; > import org.eclipse.core.internal.events.BuildCommand; > import org.eclipse.core.internal.localstore.SafeFileInputStream; >-import org.eclipse.core.internal.utils.Messages; >-import org.eclipse.core.internal.utils.Policy; >+import org.eclipse.core.internal.utils.*; > import org.eclipse.core.resources.*; > import org.eclipse.core.runtime.*; > import org.eclipse.osgi.util.NLS; >@@ -946,8 +946,7 @@ > file = new BufferedInputStream(new FileInputStream(location.toFile())); > return read(new InputSource(file)); > } finally { >- if (file != null) >- file.close(); >+ FileUtil.safeClose(file); > } > } > >Index: src/org/eclipse/core/internal/resources/ProjectPreferences.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/ProjectPreferences.java,v >retrieving revision 1.63 >diff -u -r1.63 ProjectPreferences.java >--- src/org/eclipse/core/internal/resources/ProjectPreferences.java 5 Jan 2011 11:19:33 -0000 1.63 >+++ src/org/eclipse/core/internal/resources/ProjectPreferences.java 10 Jan 2011 12:21:33 -0000 >@@ -8,6 +8,7 @@ > * Contributors: > * IBM Corporation - initial API and implementation > * Markus Schorn (Wind River) - [108066] Project prefs marked dirty on read >+ * James Blackburn (Broadcom Corp.) - ongoing development > *******************************************************************************/ > package org.eclipse.core.internal.resources; > >@@ -594,16 +595,13 @@ > ByteArrayOutputStream output = new ByteArrayOutputStream(); > try { > table.store(output, null); >+ output.close(); > } catch (IOException e) { > String message = NLS.bind(Messages.preferences_saveProblems, absolutePath()); > log(new Status(IStatus.ERROR, Platform.PI_RUNTIME, IStatus.ERROR, message, e)); > throw new BackingStoreException(message); > } finally { >- try { >- output.close(); >- } catch (IOException e) { >- // ignore >- } >+ FileUtil.safeClose(output); > } > final InputStream input = new BufferedInputStream(new ByteArrayInputStream(output.toByteArray())); > IWorkspaceRunnable operation = new IWorkspaceRunnable() { >Index: src/org/eclipse/core/internal/resources/SafeFileTable.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/SafeFileTable.java,v >retrieving revision 1.11 >diff -u -r1.11 SafeFileTable.java >--- src/org/eclipse/core/internal/resources/SafeFileTable.java 21 Feb 2005 23:10:23 -0000 1.11 >+++ src/org/eclipse/core/internal/resources/SafeFileTable.java 10 Jan 2011 12:21:33 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2005 IBM Corporation and others. >+ * Copyright (c) 2000, 2011 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -7,12 +7,14 @@ > * > * Contributors: > * IBM Corporation - initial API and implementation >+ * James Blackburn (Broadcom Corp.) - ongoing development > *******************************************************************************/ > package org.eclipse.core.internal.resources; > > import java.io.*; > import java.util.Properties; > import java.util.Set; >+import org.eclipse.core.internal.utils.FileUtil; > import org.eclipse.core.internal.utils.Messages; > import org.eclipse.core.resources.IResourceStatus; > import org.eclipse.core.resources.ResourcesPlugin; >@@ -80,8 +82,9 @@ > FileOutputStream output = new FileOutputStream(target); > try { > table.store(output, "safe table"); //$NON-NLS-1$ >- } finally { > output.close(); >+ } finally { >+ FileUtil.safeClose(output); > } > } catch (IOException e) { > String message = Messages.resources_exSafeSave; >Index: src/org/eclipse/core/internal/resources/SaveManager.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/SaveManager.java,v >retrieving revision 1.108 >diff -u -r1.108 SaveManager.java >--- src/org/eclipse/core/internal/resources/SaveManager.java 29 Nov 2010 12:10:40 -0000 1.108 >+++ src/org/eclipse/core/internal/resources/SaveManager.java 10 Jan 2011 12:21:33 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2010 IBM Corporation and others. >+ * Copyright (c) 2000, 2011 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -9,7 +9,7 @@ > * IBM Corporation - initial API and implementation > * Francis Lynch (Wind River) - [301563] Save and load tree snapshots > * Francis Lynch (Wind River) - [305718] Allow reading snapshot into renamed project >- * Broadcom Corporation - build configurations and references >+ * Broadcom Corporation - ongoing development > *******************************************************************************/ > package org.eclipse.core.internal.resources; > >@@ -17,7 +17,8 @@ > import java.net.URI; > import java.util.*; > import java.util.zip.*; >-import org.eclipse.core.filesystem.*; >+import org.eclipse.core.filesystem.EFS; >+import org.eclipse.core.filesystem.IFileStore; > import org.eclipse.core.internal.events.*; > import org.eclipse.core.internal.localstore.*; > import org.eclipse.core.internal.utils.*; >@@ -1201,8 +1202,9 @@ > try { > masterTable.store(output, "master table"); //$NON-NLS-1$ > output.succeed(); >- } finally { > output.close(); >+ } finally { >+ FileUtil.safeClose(output); > } > } catch (IOException e) { > throw new ResourceException(IResourceStatus.INTERNAL_ERROR, null, NLS.bind(Messages.resources_exSaveMaster, location.toOSString()), e); >@@ -1278,8 +1280,9 @@ > try { > output.writeInt(ICoreConstants.WORKSPACE_TREE_VERSION_2); > writeTree(project, output, monitor); >- } finally { > output.close(); >+ } finally { >+ FileUtil.safeClose(output); > } > OutputStream snapOut = store.openOutputStream(EFS.NONE, monitor); > out = new ZipOutputStream(snapOut); >@@ -1295,14 +1298,13 @@ > } > out.closeEntry(); > } finally { >- in.close(); >+ FileUtil.safeClose(in); > } >+ out.close(); > } catch (IOException e) { > throw new ResourceException(IResourceStatus.FAILED_WRITE_LOCAL, snapshotPath, Messages.resources_copyProblem, e); > } finally { >- if (out!=null) { >- try { out.close(); } catch (IOException e) { /*ignore*/ } >- } >+ FileUtil.safeClose(out); > if (tmpTree!=null) tmpTree.delete(); > } > } >@@ -1322,8 +1324,9 @@ > try { > output.writeInt(ICoreConstants.WORKSPACE_TREE_VERSION_2); > writeTree(computeStatesToSave(contexts, workspace.getElementTree()), output, monitor); >- } finally { > output.close(); >+ } finally { >+ FileUtil.safeClose(output); > } > } catch (Exception e) { > String msg = NLS.bind(Messages.resources_writeWorkspaceMeta, treeLocation); >@@ -1549,12 +1552,7 @@ > if (root.getType() != IResource.ROOT) > o2 = new DataOutputStream(new SafeFileOutputStream(syncInfoLocation.toOSString(), syncInfoTempLocation.toOSString())); > } catch (IOException e) { >- if (o1 != null) >- try { >- o1.close(); >- } catch (IOException e2) { >- // ignore >- } >+ FileUtil.safeClose(o1); > message = NLS.bind(Messages.resources_writeMeta, root.getFullPath()); > throw new ResourceException(IResourceStatus.FAILED_WRITE_METADATA, root.getFullPath(), message, e); > } >@@ -1610,8 +1608,11 @@ > removeGarbage(markersOutput, markersLocation, markersTempLocation); > // if we have the workspace root the output stream will be null and we > // don't have to perform cleanup code >- if (syncInfoOutput != null) >+ if (syncInfoOutput != null) { > removeGarbage(syncInfoOutput, syncInfoLocation, syncInfoTempLocation); >+ syncInfoOutput.close(); >+ } >+ markersOutput.close(); > } catch (IOException e) { > message = NLS.bind(Messages.resources_writeMeta, root.getFullPath()); > throw new ResourceException(IResourceStatus.FAILED_WRITE_METADATA, root.getFullPath(), message, e); >@@ -1719,8 +1720,11 @@ > System.out.println("Snap SyncInfo for " + root.getFullPath() + ": " + snapTimes[1] + "ms"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ > if (markerFileSize != markersOutput.size()) > safeMarkerStream.succeed(); >- if (safeSyncInfoStream != null && syncInfoFileSize != syncInfoOutput.size()) >+ if (safeSyncInfoStream != null && syncInfoFileSize != syncInfoOutput.size()) { > safeSyncInfoStream.succeed(); >+ syncInfoOutput.close(); >+ } >+ markersOutput.close(); > } catch (IOException e) { > message = NLS.bind(Messages.resources_writeMeta, root.getFullPath()); > throw new ResourceException(IResourceStatus.FAILED_WRITE_METADATA, root.getFullPath(), message, e); >@@ -1969,9 +1973,9 @@ > output.writeUTF((String) it.next()); > for (Iterator it = additionalConfigNames.iterator(); it.hasNext();) > output.writeUTF((String) it.next()); >+ output.close(); > } finally { >- if (output != null) >- output.close(); >+ FileUtil.safeClose(output); > if (!wasImmutable) > workspace.newWorkingTree(); > } >@@ -1990,8 +1994,9 @@ > DataOutputStream output = new DataOutputStream(safe); > output.writeInt(ICoreConstants.WORKSPACE_TREE_VERSION_2); > writeTree(project, output, null); >- } finally { > safe.close(); >+ } finally { >+ FileUtil.safeClose(safe); > } > } catch (IOException e) { > String msg = NLS.bind(Messages.resources_writeMeta, project.getFullPath()); >Index: src/org/eclipse/core/internal/utils/FileUtil.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.core.resources/src/org/eclipse/core/internal/utils/FileUtil.java,v >retrieving revision 1.19 >diff -u -r1.19 FileUtil.java >--- src/org/eclipse/core/internal/utils/FileUtil.java 17 Nov 2008 04:21:23 -0000 1.19 >+++ src/org/eclipse/core/internal/utils/FileUtil.java 10 Jan 2011 12:21:33 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2005, 2008 IBM Corporation and others. >+ * Copyright (c) 2005, 2011 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -8,6 +8,7 @@ > * Contributors: > * IBM Corporation - initial API and implementation > * Martin Oberhuber (Wind River) - [44107] Add symbolic links to ResourceAttributes API >+ * James Blackburn (Broadcom Corp.) - ongoing development > *******************************************************************************/ > package org.eclipse.core.internal.utils; > >@@ -175,25 +176,25 @@ > * Closes a stream and ignores any resulting exception. This is useful > * when doing stream cleanup in a finally block where secondary exceptions > * are not worth logging. >+ * >+ *<p> >+ * <strong>WARNING:</strong> >+ * If the API contract requires notifying clients of I/O problems, then you <strong>must</strong> >+ * explicitly close() output streams outside of safeClose(). >+ * Some OutputStreams will defer an IOException from write() to close(). So >+ * while the writes may 'succeed', ignoring the IOExcpetion will result in silent >+ * data loss. >+ * </p> >+ * <p> >+ * This method should only be used as a fail-safe to ensure resources are not >+ * leaked. >+ * </p> >+ * See also: https://bugs.eclipse.org/bugs/show_bug.cgi?id=332543 > */ >- public static void safeClose(InputStream in) { >- try { >- if (in != null) >- in.close(); >- } catch (IOException e) { >- //ignore >- } >- } >- >- /** >- * Closes a stream and ignores any resulting exception. This is useful >- * when doing stream cleanup in a finally block where secondary exceptions >- * are not worth logging. >- */ >- public static void safeClose(OutputStream out) { >+ public static void safeClose(Closeable stream) { > try { >- if (out != null) >- out.close(); >+ if (stream != null) >+ stream.close(); > } catch (IOException e) { > //ignore > } >@@ -233,9 +234,12 @@ > String msg = NLS.bind(Messages.localstore_failedReadDuringWrite, path); > throw new ResourceException(IResourceStatus.FAILED_READ_LOCAL, new Path(path), msg, e); > } >- if (bytesRead == -1) >- break; > try { >+ if (bytesRead == -1) { >+ // Bug 332543 - ensure we don't ignore failures on close() >+ destination.close(); >+ break; >+ } > destination.write(buffer, 0, bytesRead); > } catch (IOException e) { > String msg = NLS.bind(Messages.localstore_couldNotWrite, path); >#P org.eclipse.core.tests.resources >Index: src/org/eclipse/core/tests/internal/filesystem/wrapper/WrapperFileStore.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/filesystem/wrapper/WrapperFileStore.java,v >retrieving revision 1.4 >diff -u -r1.4 WrapperFileStore.java >--- src/org/eclipse/core/tests/internal/filesystem/wrapper/WrapperFileStore.java 20 May 2009 23:50:57 -0000 1.4 >+++ src/org/eclipse/core/tests/internal/filesystem/wrapper/WrapperFileStore.java 10 Jan 2011 12:21:35 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2006, 2008 IBM Corporation and others. >+ * Copyright (c) 2006, 2011 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -7,6 +7,7 @@ > * > * Contributors: > * IBM Corporation - initial API and implementation >+ * James Blackburn (Broadcom Corp.) - ongoing development > *******************************************************************************/ > package org.eclipse.core.tests.internal.filesystem.wrapper; > >@@ -28,6 +29,19 @@ > this.baseStore = baseStore; > } > >+ public static IFileStore newInstance(Class<? extends WrapperFileStore> clazz, IFileStore baseStore) { >+ try { >+ return clazz.getConstructor(IFileStore.class).newInstance(baseStore); >+ } catch (Exception e) { >+ // Test infrastructure failure... >+ throw new Error(e); >+ } >+ } >+ >+ protected IFileStore createNewWrappedStore(IFileStore store) { >+ return newInstance(getClass(), store); >+ } >+ > public IFileInfo[] childInfos(int options, IProgressMonitor monitor) throws CoreException { > return baseStore.childInfos(options, monitor); > } >@@ -40,7 +54,7 @@ > IFileStore[] childStores = baseStore.childStores(options, monitor); > for (int i = 0; i < childStores.length; i++) > // replace ordinary file store with wrapper version >- childStores[i] = new WrapperFileStore(childStores[i]); >+ childStores[i] = createNewWrappedStore(childStores[i]); > return childStores; > } > >@@ -73,15 +87,15 @@ > } > > public IFileStore getChild(IPath path) { >- return new WrapperFileStore(baseStore.getChild(path)); >+ return createNewWrappedStore(baseStore.getChild(path)); > } >- >+ > public IFileStore getFileStore(IPath path) { >- return new WrapperFileStore(baseStore.getFileStore(path)); >+ return createNewWrappedStore(baseStore.getFileStore(path)); > } > > public IFileStore getChild(String name) { >- return new WrapperFileStore(baseStore.getChild(name)); >+ return createNewWrappedStore(baseStore.getChild(name)); > } > > public IFileSystem getFileSystem() { >@@ -94,7 +108,7 @@ > > public IFileStore getParent() { > IFileStore baseParent = baseStore.getParent(); >- return baseParent == null ? null : new WrapperFileStore(baseParent); >+ return baseParent == null ? null : createNewWrappedStore(baseParent); > } > > public int hashCode() { >Index: src/org/eclipse/core/tests/internal/filesystem/wrapper/WrapperFileSystem.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/filesystem/wrapper/WrapperFileSystem.java,v >retrieving revision 1.1 >diff -u -r1.1 WrapperFileSystem.java >--- src/org/eclipse/core/tests/internal/filesystem/wrapper/WrapperFileSystem.java 27 Mar 2006 23:00:24 -0000 1.1 >+++ src/org/eclipse/core/tests/internal/filesystem/wrapper/WrapperFileSystem.java 10 Jan 2011 12:21:35 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2006 IBM Corporation and others. >+ * Copyright (c) 2006, 2011 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -7,6 +7,7 @@ > * > * Contributors: > * IBM Corporation - initial API and implementation >+ * James Blackburn (Broadcom Corp.) - ongoing development > *******************************************************************************/ > package org.eclipse.core.tests.internal.filesystem.wrapper; > >@@ -22,27 +23,50 @@ > /** > * A simple file system implementation that acts as a wrapper around the > * local file system. >+ * <p> >+ * Also allows tests to inject a custom FileStore template class (derived from >+ * {@link WrapperFileStore}). Tests can use {@link #setCustomFileStore(Class)} >+ * to override default {@link WrapperFileStore} behaviour. >+ * </p> > */ > public class WrapperFileSystem extends FileSystem { > >- private static final IFileStore NULL_ROOT = EFS.getNullFileSystem().getStore(Path.ROOT); >+ protected static final IFileStore NULL_ROOT = EFS.getNullFileSystem().getStore(Path.ROOT); > > private static final String SCHEME_WRAPPED = "wrapped"; > >- private static WrapperFileSystem instance; >+ private static volatile WrapperFileSystem instance; >+ >+ /** Custom file-store wrapper */ >+ private static volatile Class<? extends WrapperFileStore> customFS = WrapperFileStore.class; > > public static URI getBasicURI(URI wrappedURI) { > Assert.isLegal(SCHEME_WRAPPED.equals(wrappedURI.getScheme())); > return URI.create(wrappedURI.getQuery()); > } > >- public static WrapperFileSystem getInstance() { >- WrapperFileSystem tmpInstance = instance; >- if (tmpInstance != null) >- return tmpInstance; >+ public static synchronized WrapperFileSystem getInstance() { >+ if (instance != null) >+ return instance; > return instance = new WrapperFileSystem(); > } > >+ /** >+ * Use fs as the WrapperFileStore to use in this filesystem. >+ * Allows tests to easily override existing IFileStore behaviour. >+ * By extending {@link WrapperFileStore} conditions difficult to simulate >+ * on the LocalFileSystem can be provoked. >+ * >+ * @param fs filestore, or null to use default {@link WrapperFileStore} >+ * based implementation. >+ */ >+ public static void setCustomFileStore(Class<? extends WrapperFileStore> fs) { >+ if (fs == null) >+ customFS = WrapperFileStore.class; >+ else >+ customFS = fs; >+ } >+ > public static URI getWrappedURI(URI baseURI) { > try { > return new URI(SCHEME_WRAPPED, null, baseURI.getPath(), baseURI.toString(), null); >@@ -69,6 +93,6 @@ > CoreTest.log(ResourceTest.PI_RESOURCES_TESTS, e); > return NULL_ROOT; > } >- return new WrapperFileStore(baseStore); >+ return WrapperFileStore.newInstance(customFS, baseStore); > } > } >Index: src/org/eclipse/core/tests/resources/ResourceTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/ResourceTest.java,v >retrieving revision 1.25 >diff -u -r1.25 ResourceTest.java >--- src/org/eclipse/core/tests/resources/ResourceTest.java 20 Jan 2010 15:21:01 -0000 1.25 >+++ src/org/eclipse/core/tests/resources/ResourceTest.java 10 Jan 2011 12:21:35 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2010 IBM Corporation and others. >+ * Copyright (c) 2000, 2011 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -7,6 +7,7 @@ > * > * Contributors: > * IBM Corporation - initial API and implementation >+ * James Blackburn (Broadcom Corp.) - ongoing development > *******************************************************************************/ > package org.eclipse.core.tests.resources; > >@@ -773,6 +774,7 @@ > try { > os = new FileOutputStream(osFile); > os.write(newContent.getBytes("UTF8")); >+ os.close(); > } finally { > FileUtil.safeClose(os); > } >Index: src/org/eclipse/core/tests/resources/regression/AllTests.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/AllTests.java,v >retrieving revision 1.44 >diff -u -r1.44 AllTests.java >--- src/org/eclipse/core/tests/resources/regression/AllTests.java 5 Jan 2011 15:08:26 -0000 1.44 >+++ src/org/eclipse/core/tests/resources/regression/AllTests.java 10 Jan 2011 12:21:35 -0000 >@@ -7,6 +7,7 @@ > * > * Contributors: > * IBM Corporation - initial API and implementation >+ * James Blackburn (Broadcom Corp.) - ongoing development > *******************************************************************************/ > package org.eclipse.core.tests.resources.regression; > >@@ -59,6 +60,7 @@ > suite.addTest(Bug_288315.suite()); > suite.addTest(Bug_329836.suite()); > suite.addTest(Bug_331445.suite()); >+ suite.addTest(Bug_332543.suite()); > suite.addTest(IFileTest.suite()); > suite.addTest(IFolderTest.suite()); > suite.addTest(IProjectTest.suite()); >Index: src/org/eclipse/core/tests/resources/regression/Bug_332543.java >=================================================================== >RCS file: src/org/eclipse/core/tests/resources/regression/Bug_332543.java >diff -N src/org/eclipse/core/tests/resources/regression/Bug_332543.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/tests/resources/regression/Bug_332543.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,108 @@ >+/******************************************************************************* >+ * Copyright (c) 2011 Broadcom Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * James Blackburn (Broadcom Corp.) - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.core.tests.resources.regression; >+ >+import java.io.*; >+import java.net.URI; >+import junit.framework.Test; >+import junit.framework.TestSuite; >+import org.eclipse.core.filesystem.IFileStore; >+import org.eclipse.core.filesystem.URIUtil; >+import org.eclipse.core.resources.*; >+import org.eclipse.core.runtime.*; >+import org.eclipse.core.tests.internal.filesystem.wrapper.WrapperFileStore; >+import org.eclipse.core.tests.internal.filesystem.wrapper.WrapperFileSystem; >+import org.eclipse.core.tests.resources.ResourceTest; >+ >+/** >+ * This tests that I/O Exception on OuptuStream#close() after IFile#setContents is correctly reported. >+ */ >+public class Bug_332543 extends ResourceTest { >+ >+ public static Test suite() { >+ return new TestSuite(Bug_332543.class); >+ } >+ >+ /** >+ * Wrapper FS which throws an IOException when someone >+ * closes an output stream... >+ */ >+ public static class IOErrOnCloseFileStore extends WrapperFileStore { >+ public IOErrOnCloseFileStore(IFileStore store) { >+ super(store); >+ } >+ >+ public OutputStream openOutputStream(int options, IProgressMonitor monitor) throws CoreException { >+ OutputStream os = super.openOutputStream(options, monitor); >+ os = new BufferedOutputStream(os) { >+ public void close() throws java.io.IOException { >+ // We close the output stream (so there aren't issues deleting the project during tear-down) >+ super.close(); >+ // But we also throw IOException as if the operation had failed. >+ throw new IOException("Whoops I dunno how to close!"); >+ } >+ }; >+ return os; >+ } >+ } >+ >+ @Override >+ protected void setUp() throws Exception { >+ super.setUp(); >+ } >+ >+ @Override >+ protected void tearDown() throws Exception { >+ WrapperFileSystem.setCustomFileStore(null); >+ super.tearDown(); >+ } >+ >+ public void testBug() throws Exception { >+ IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); >+ >+ String proj_name = getUniqueString(); >+ IPath proj_loc = root.getLocation().append(proj_name); >+ URI proj_uri = WrapperFileSystem.getWrappedURI(URIUtil.toURI(proj_loc)); >+ >+ IProjectDescription desc = ResourcesPlugin.getWorkspace().newProjectDescription(proj_name); >+ desc.setLocationURI(proj_uri); >+ // Create the project on the wrapped file system >+ IProject project = root.getProject(desc.getName()); >+ project.create(desc, getMonitor()); >+ >+ // Create a file in the project >+ IFile f = project.getFile("foo.txt"); >+ ensureExistsInFileSystem(f); >+ >+ // Set our evil IOException on close() fs. >+ WrapperFileSystem.setCustomFileStore(IOErrOnCloseFileStore.class); >+ >+ // Now open the project >+ project.open(getMonitor()); >+ >+ // Try #setContents on an existing file >+ try { >+ f.setContents(new ByteArrayInputStream("Random".getBytes()), false, true, getMonitor()); >+ fail("1.0"); >+ } catch (CoreException e) { >+ // This is expected. >+ } >+ >+ // Try create on a non-existent file >+ f = project.getFile("foo1.txt"); >+ try { >+ f.create(new ByteArrayInputStream("Random".getBytes()), false, getMonitor()); >+ fail("2.0"); >+ } catch (CoreException e) { >+ // This is expected. >+ } >+ } >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 332543
:
186165
|
186166
| 186381