Skip to main content
summaryrefslogtreecommitdiffstats
blob: 39387390fa4694b93ca1d5575ebfe8a51a0578c5 (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
package org.eclipse.team.internal.ccvs.core.client;

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

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.team.ccvs.core.ICVSFile;
import org.eclipse.team.ccvs.core.ICVSFolder;
import org.eclipse.team.internal.ccvs.core.CVSException;
import org.eclipse.team.internal.ccvs.core.util.Assert;

/**
 * Handles a "Copy-file" response from the CVS server.
 * <p>
 * Suppose as a result of performing a command the CVS server responds
 * as follows:<br>
 * <pre>
 *   [...]
 *   Copy-file myproject/ \n
 *   /u/cvsroot/myproject/oldfile.txt \n
 *   newfile.txt
 *   [...]
 * </pre>
 * Then we copy (or optionally rename) the local file "oldfile.txt" in
 * folder "myproject" to "newfile.txt".  This response is used to create
 * a backup copy of an existing file before merging in new changes.
 * </p>
 */
class CopyHandler extends ResponseHandler {
	public String getResponseID() {
		return "Copy-file"; //$NON-NLS-1$
	}

	public void handle(Session session, String localDir,
		IProgressMonitor monitor) throws CVSException {
		// read additional data for the response
		String repositoryFile = session.readLine();
		String newFile = session.readLine();
		if (session.isNoLocalChanges()) return;

		// Get the local file		
		String fileName = repositoryFile.substring(repositoryFile.lastIndexOf("/") + 1); //$NON-NLS-1$
		ICVSFolder mParent = session.getLocalRoot().getFolder(localDir);
		ICVSFile mFile = mParent.getFile(fileName);

		Assert.isTrue(mParent.exists());
		Assert.isTrue(mFile.exists() && mFile.isManaged());
		
		// rename the file
		mFile.moveTo(newFile);
	}
}

Back to the top