Lines 12-17
Link Here
|
12 |
|
12 |
|
13 |
import java.io.*; |
13 |
import java.io.*; |
14 |
import java.util.*; |
14 |
import java.util.*; |
|
|
15 |
import java.util.zip.*; |
15 |
import org.eclipse.core.internal.events.*; |
16 |
import org.eclipse.core.internal.events.*; |
16 |
import org.eclipse.core.internal.localstore.*; |
17 |
import org.eclipse.core.internal.localstore.*; |
17 |
import org.eclipse.core.internal.utils.*; |
18 |
import org.eclipse.core.internal.utils.*; |
Lines 708-713
Link Here
|
708 |
} |
709 |
} |
709 |
|
710 |
|
710 |
/** |
711 |
/** |
|
|
712 |
* Restores the contents of this project from a refresh snapshot. Throw an exception |
713 |
* if the snapshot is found but an error occurs when reading the file. |
714 |
* @return <code><code>true</code> if the project data was restored successfully, |
715 |
* and <code>false</code> if the refresh snapshot was not found or could not be opened. |
716 |
* @exception CoreException if an error occurred reading the snapshot file. |
717 |
*/ |
718 |
protected boolean restoreFromRefreshSnapshot(Project project, IProgressMonitor monitor) throws CoreException { |
719 |
boolean status = true; |
720 |
if (Policy.DEBUG_RESTORE) |
721 |
System.out.println("Restore project " + project.getFullPath() + ": starting..."); //$NON-NLS-1$ //$NON-NLS-2$ |
722 |
long start = System.currentTimeMillis(); |
723 |
monitor = Policy.monitorFor(monitor); |
724 |
try { |
725 |
monitor.beginTask("", 40); //$NON-NLS-1$ |
726 |
status = restoreTreeFromRefreshSnapshot(project, Policy.subMonitorFor(monitor, 40)); |
727 |
if (status) { |
728 |
// load the project description and set internal description |
729 |
ProjectDescription description = workspace.getFileSystemManager().read(project, true); |
730 |
project.internalSetDescription(description, false); |
731 |
} |
732 |
} finally { |
733 |
monitor.done(); |
734 |
} |
735 |
if (Policy.DEBUG_RESTORE) |
736 |
System.out.println("Restore project " + project.getFullPath() + ": " + (System.currentTimeMillis() - start) + "ms"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
737 |
return status; |
738 |
} |
739 |
|
740 |
/** |
711 |
* Reads the markers which were originally saved |
741 |
* Reads the markers which were originally saved |
712 |
* for the tree rooted by the given resource. |
742 |
* for the tree rooted by the given resource. |
713 |
*/ |
743 |
*/ |
Lines 970-975
Link Here
|
970 |
return true; |
1000 |
return true; |
971 |
} |
1001 |
} |
972 |
|
1002 |
|
|
|
1003 |
/** |
1004 |
* Restores a tree saved as a refresh snapshot to a local file. |
1005 |
* @return <code>true</code> if the snapshot exists, <code>false</code> otherwise. |
1006 |
* @exception CoreException if the project could not be restored. |
1007 |
*/ |
1008 |
protected boolean restoreTreeFromRefreshSnapshot(Project project, IProgressMonitor monitor) throws CoreException { |
1009 |
long start = System.currentTimeMillis(); |
1010 |
monitor = Policy.monitorFor(monitor); |
1011 |
String message; |
1012 |
try { |
1013 |
monitor.beginTask("", Policy.totalWork); //$NON-NLS-1$ |
1014 |
IPath projectLocation = project.getLocation(); |
1015 |
if (projectLocation == null){ |
1016 |
//TODO handle case where project is on remote store |
1017 |
return false; |
1018 |
} |
1019 |
IPath snapshotLocation = projectLocation.append(IProject.REFRESH_SNAPSHOT_FILE_LOCATION); |
1020 |
java.io.File zipFile = snapshotLocation.toFile(); |
1021 |
if (!zipFile.exists()) |
1022 |
return false; |
1023 |
ZipFile zip = new ZipFile(zipFile); |
1024 |
ZipEntry treeEntry = zip.getEntry("resource-index.tree"); //$NON-NLS-1$ |
1025 |
if (treeEntry == null) { |
1026 |
zip.close(); |
1027 |
return false; |
1028 |
} |
1029 |
InputStream is = zip.getInputStream(treeEntry); |
1030 |
DataInputStream input = new DataInputStream(is); |
1031 |
try { |
1032 |
WorkspaceTreeReader reader = WorkspaceTreeReader.getReader(workspace, input.readInt()); |
1033 |
reader.readTree(project, input, Policy.subMonitorFor(monitor, Policy.totalWork)); |
1034 |
} finally { |
1035 |
input.close(); |
1036 |
zip.close(); |
1037 |
} |
1038 |
} catch (IOException e) { |
1039 |
message = NLS.bind(Messages.resources_readMeta, project.getFullPath()); |
1040 |
throw new ResourceException(IResourceStatus.FAILED_READ_METADATA, project.getFullPath(), message, e); |
1041 |
} finally { |
1042 |
monitor.done(); |
1043 |
} |
1044 |
if (Policy.DEBUG_RESTORE_TREE) { |
1045 |
System.out.println("Restore Tree for " + project.getFullPath() + ": " + (System.currentTimeMillis() - start) + "ms"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
1046 |
} |
1047 |
return true; |
1048 |
} |
1049 |
|
973 |
class InternalMonitorWrapper extends ProgressMonitorWrapper{ |
1050 |
class InternalMonitorWrapper extends ProgressMonitorWrapper{ |
974 |
private boolean ignoreCancel; |
1051 |
private boolean ignoreCancel; |
975 |
|
1052 |
|
Lines 1640-1645
Link Here
|
1640 |
info.writeTo(output); |
1717 |
info.writeTo(output); |
1641 |
} |
1718 |
} |
1642 |
|
1719 |
|
|
|
1720 |
public void writeRefreshSnapshot(Project project, IProgressMonitor monitor) throws CoreException { |
1721 |
String snapshotPath = IProject.REFRESH_SNAPSHOT_FILE_LOCATION; |
1722 |
IPath snapshotLocation = project.getLocation().append(snapshotPath); |
1723 |
java.io.File tmpTree = null; |
1724 |
try { |
1725 |
tmpTree = java.io.File.createTempFile("tmp", ".tree"); //$NON-NLS-1$//$NON-NLS-2$ |
1726 |
} catch (IOException e) { |
1727 |
throw new ResourceException(IResourceStatus.FAILED_WRITE_LOCAL, snapshotLocation, Messages.resources_copyProblem, e); |
1728 |
} |
1729 |
java.io.File snapshotLocationFile = snapshotLocation.toFile(); |
1730 |
snapshotLocationFile.delete(); |
1731 |
ZipOutputStream out = null; |
1732 |
try { |
1733 |
FileOutputStream fis = new FileOutputStream(tmpTree); |
1734 |
DataOutputStream output = new DataOutputStream(fis); |
1735 |
try { |
1736 |
output.writeInt(ICoreConstants.WORKSPACE_TREE_VERSION_2); |
1737 |
writeTree(project, output, null); |
1738 |
} finally { |
1739 |
output.close(); |
1740 |
} |
1741 |
snapshotLocationFile.getParentFile().mkdirs(); |
1742 |
out = new ZipOutputStream(new FileOutputStream(snapshotLocationFile)); |
1743 |
out.setLevel(Deflater.BEST_COMPRESSION); |
1744 |
ZipEntry e = new ZipEntry("resource-index.tree"); //$NON-NLS-1$ |
1745 |
out.putNextEntry(e); |
1746 |
int read = 0; |
1747 |
byte[] buffer = new byte[4096]; |
1748 |
InputStream in = new FileInputStream(tmpTree); |
1749 |
try { |
1750 |
while ((read = in.read(buffer)) >= 0) { |
1751 |
out.write(buffer, 0, read); |
1752 |
} |
1753 |
out.closeEntry(); |
1754 |
} finally { |
1755 |
in.close(); |
1756 |
} |
1757 |
out.close(); |
1758 |
tmpTree.delete(); |
1759 |
} catch (IOException e) { |
1760 |
throw new ResourceException(IResourceStatus.FAILED_WRITE_LOCAL, snapshotLocation, Messages.resources_copyProblem, e); |
1761 |
} |
1762 |
monitor.worked(1); |
1763 |
} |
1764 |
|
1643 |
protected void writeTree(Map statesToSave, DataOutputStream output, IProgressMonitor monitor) throws IOException, CoreException { |
1765 |
protected void writeTree(Map statesToSave, DataOutputStream output, IProgressMonitor monitor) throws IOException, CoreException { |
1644 |
monitor = Policy.monitorFor(monitor); |
1766 |
monitor = Policy.monitorFor(monitor); |
1645 |
try { |
1767 |
try { |