Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 34822f65194e84d46e9cb87104a176b51863eb03 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package org.eclipse.team.internal.ccvs.core.response;

/*
 * (c) Copyright IBM Corp. 2000, 2001.
 * All Rights Reserved.
 */

import java.io.InputStream;
import java.io.PrintStream;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.team.internal.ccvs.core.CVSException;
import org.eclipse.team.internal.ccvs.core.Policy;
import org.eclipse.team.internal.ccvs.core.connection.Connection;
import org.eclipse.team.internal.ccvs.core.resources.api.FileProperties;
import org.eclipse.team.internal.ccvs.core.resources.api.IManagedFile;
import org.eclipse.team.internal.ccvs.core.resources.api.IManagedFolder;
import org.eclipse.team.internal.ccvs.core.util.Assert;
import org.eclipse.team.internal.ccvs.core.util.Util;

/**
 * Response on the "Updated" or "Merged" token form the server.
 * 
 * Does get information about the file that is updated
 * and the file-content itself and puts it on the fileSystem.
 * 
 * The difference beetween the "Updated" and the "Merged" is, that
 * an "Merged" file is not going to be up-to-date after the operation.
 * 
 * Requiers a exisiting parent-folder.
 */
class Updated extends ResponseHandler {
	
	public static final String UPDATE_NAME = "Updated";
	public static final String MERGE_NAME = "Merged";
	
	private static final String READ_ONLY_FLAG = "u=rw";
	
	private final ModTimeHandler modTimeHandler;
	private final boolean upToDate;
	
	/**
	 * @param upToDate => Updated-Handler
	 * @param !upToDate => Merged-Handler
	 */
	public Updated(ModTimeHandler modTimeHandler, boolean upToDate) {
		this.modTimeHandler = modTimeHandler;
		this.upToDate = upToDate;
	}
	
	public String getName() {
		if (upToDate) {
			return UPDATE_NAME;
		} else {
			return MERGE_NAME;
		}
	}

	/**
	 * Get the realative Path of the resource in comparison to
	 * the homedirectory.
	 * 
	 * This is used to save it while storing the Properties
	 * for a folder (the Repository-file)
	 */	
	public static String getRepository(Connection connection, String resourceName) 
		throws CVSException {
			
		return Util.getRelativePath(connection.getRootDirectory(),
												resourceName);
	}

	public void handle(Connection connection, 
							PrintStream messageOutput,
							IManagedFolder mRoot,
							IProgressMonitor monitor) 
							throws CVSException {
							
		String fileName;
		int size;
		boolean binary;
		boolean readOnly;
		
		IManagedFile mFile;
		IManagedFolder mParent;
		FileProperties fileInfo;
		
		InputStream in;
				
		// Read the info associated with the Updated response
		String localDirectory = connection.readLine();
		String repositoryFilename = connection.readLine();
		String entry = connection.readLine();
		String permissions = connection.readLine();
		
		// Read the number of bytes in the file
		String line = connection.readLine();

		try {
			size = Integer.parseInt(line);
		} catch (NumberFormatException e) {
			throw new CVSException(Policy.bind("Updated.numberFormat"));
		}
		
		// Get the local file		
		fileName = repositoryFilename.substring(
						repositoryFilename.lastIndexOf(SERVER_DELIM) + 1);
		mParent = mRoot.getFolder(localDirectory);
		Assert.isTrue(mParent.exists() && mParent.isCVSFolder());
		mFile = mParent.getFile(fileName);
		
		in = connection.getResponseStream();

		fileInfo = new FileProperties(entry, permissions);
		binary = fileInfo.getKeywordMode().indexOf(FileProperties.BINARY_TAG) != -1;
		readOnly = permissions.indexOf(READ_ONLY_FLAG) == -1;
		
		mFile.receiveFrom(in,monitor,size,binary,readOnly);
		
		// Set the timestamp in the file
		// set the result in the fileInfo
		mFile.setTimeStamp(modTimeHandler.pullLastTime());
		if (upToDate) {
			fileInfo.setTimeStamp(mFile.getTimeStamp());
		} else {
			fileInfo.setTimeStamp(RESULT_OF_MERGE + mFile.getTimeStamp());
		}			
		mFile.setFileInfo(fileInfo);

		Assert.isTrue(mFile.isDirty()!=upToDate);
	}
}

Back to the top