1 12 package org.eclipse.team.internal.ccvs.core.client; 13 14 import java.util.Date ; 15 16 import org.eclipse.core.runtime.IProgressMonitor; 17 import org.eclipse.team.internal.ccvs.core.*; 18 import org.eclipse.team.internal.ccvs.core.syncinfo.MutableResourceSyncInfo; 19 import org.eclipse.team.internal.ccvs.core.syncinfo.ResourceSyncInfo; 20 21 35 36 45 public class UpdatedHandler extends ResponseHandler { 46 47 private int handlerType; 48 49 public static final int HANDLE_UPDATED = ICVSFile.UPDATED; 50 public static final int HANDLE_MERGED = ICVSFile.MERGED; 51 public static final int HANDLE_UPDATE_EXISTING = ICVSFile.UPDATE_EXISTING; 52 public static final int HANDLE_CREATED = ICVSFile.CREATED; 53 54 private static final String READ_ONLY_FLAG = "u=rw"; private static final String EXECUTE_FLAG = "x"; 57 public UpdatedHandler(int handlerType) { 58 this.handlerType = handlerType; 59 } 60 61 public String getResponseID() { 62 switch (handlerType) { 63 case HANDLE_UPDATED: return "Updated"; case HANDLE_MERGED: return "Merged"; case HANDLE_UPDATE_EXISTING: return "Update-existing"; case HANDLE_CREATED: return "Created"; } 68 return null; 69 } 70 71 public void handle(Session session, String localDir, IProgressMonitor monitor) throws CVSException { 72 String repositoryFile = session.readLine(); 74 String entryLine = session.readLine(); 75 byte[] entryBytes = entryLine.getBytes(); 76 String permissionsLine = session.readLine(); 77 78 Date modTime = session.getModTime(); 80 session.setModTime(null); 81 82 String fileName = repositoryFile.substring(repositoryFile.lastIndexOf("/") + 1); ICVSFolder mParent = getExistingFolder(session, localDir); 85 ICVSFile mFile = getTargetFile(mParent, fileName, entryBytes); 86 87 boolean binary = ResourceSyncInfo.isBinary(entryBytes); 88 boolean readOnly = permissionsLine.indexOf(READ_ONLY_FLAG) == -1; 89 boolean executable = permissionsLine.indexOf(EXECUTE_FLAG) != -1; 90 91 try { 92 if (mFile.isReadOnly()) mFile.setReadOnly(false); 94 } catch (CVSException e) { 95 CVSProviderPlugin.log(e); 97 } 98 99 try { 100 receiveTargetFile(session, mFile, entryLine, modTime, binary, readOnly, executable, monitor); 101 } catch (CVSException e) { 102 if (!handleInvalidResourceName(session, mFile, e)) { 107 throw e; 108 } 109 } 110 } 111 112 protected ICVSFile getTargetFile(ICVSFolder mParent, String fileName, byte[] entryBytes) throws CVSException { 113 return mParent.getFile(fileName); 114 } 115 116 protected void receiveTargetFile(Session session, ICVSFile mFile, String entryLine, Date modTime, boolean binary, boolean readOnly, boolean executable, IProgressMonitor monitor) throws CVSException { 117 118 session.receiveFile(mFile, binary, handlerType, monitor); 120 121 mFile.setTimeStamp(modTime); 124 modTime = mFile.getTimeStamp(); 125 ResourceSyncInfo info = new ResourceSyncInfo(entryLine, null); 126 MutableResourceSyncInfo newInfoWithTimestamp = info.cloneMutable(); 127 newInfoWithTimestamp.setTimeStamp(modTime); 128 129 CVSTag tag = newInfoWithTimestamp.getTag(); 131 if(tag != null && CVSTag.BASE.getName().equals(tag.getName())){ 132 newInfoWithTimestamp.setTag(mFile.getSyncInfo().getTag()); 133 } 134 135 int modificationState = ICVSFile.UNKNOWN; 136 if(handlerType==HANDLE_MERGED) { 137 newInfoWithTimestamp.setMerged(); 138 } else if (!session.isIgnoringLocalChanges() 139 && !info.isAdded() 140 && (handlerType==HANDLE_UPDATE_EXISTING || handlerType==HANDLE_CREATED)) { 141 modificationState = ICVSFile.CLEAN; 144 CVSProviderPlugin.getPlugin().getFileModificationManager().updated(mFile); 145 } 146 mFile.setSyncInfo(newInfoWithTimestamp, modificationState); 147 try { 148 if (readOnly) mFile.setReadOnly(true); 149 if (executable) mFile.setExecutable(true); 150 } catch (CVSException e) { 151 CVSProviderPlugin.log(e); 153 } 154 } 155 156 public int getHandlerType() { 157 return handlerType; 158 } 159 160 } 161 | Popular Tags |