Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 8fe0821173935bc7d38d9773399e37123c7fd391 (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
/*******************************************************************************
 * Copyright (c) 2014 Wind River Systems, Inc.
 * 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:
 *    Markus Schorn - initial API and implementation
 *******************************************************************************/

package org.eclipse.tcf.te.tcf.remote.core.operation;

import org.eclipse.core.filesystem.EFS;
import org.eclipse.core.filesystem.IFileInfo;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.tcf.protocol.IToken;
import org.eclipse.tcf.services.IFileSystem;
import org.eclipse.tcf.services.IFileSystem.DoneSetStat;
import org.eclipse.tcf.services.IFileSystem.DoneStat;
import org.eclipse.tcf.services.IFileSystem.FileAttrs;
import org.eclipse.tcf.services.IFileSystem.FileSystemException;
import org.eclipse.tcf.te.tcf.remote.core.TCFFileStore;
import org.eclipse.tcf.te.tcf.remote.core.operation.PeerInfo.DoneGetFileSystem;

public final class TCFOperationPutInfo extends TCFFileStoreOperation<Object> {

    private final boolean fSetAttribs;
	private final boolean fSetLastModified;
	private final IFileInfo fFileInfo;

	public TCFOperationPutInfo(TCFFileStore fileStore, IFileInfo info, boolean setAttribs, boolean setLastModified) {
    	super(fileStore);
    	fFileInfo = info;
    	fSetAttribs = setAttribs;
    	fSetLastModified = setLastModified;
    }

	protected IFileInfo getFileInfo() {
	    return fFileInfo;
    }

	protected boolean isSetAttribs() {
	    return fSetAttribs;
    }

	protected boolean isSetLastModified() {
	    return fSetLastModified;
    }

	@Override
    protected void doExecute() {
    	getFileSystem(new DoneGetFileSystem() {
    		@Override
    		public void done(final IFileSystem fileSystem, IStatus status) {
    			if (shallAbort(status))
    				return;
    			stat(fileSystem, getFileStore(), new DoneStat() {
    				@Override
    				public void doneStat(IToken token, FileSystemException error, FileAttrs attrs) {
    					if (shallAbort(error))
    						return;
    					int p = attrs.permissions;
						long mtime = attrs.mtime;
						IFileInfo i = getFileInfo();
						if (isSetAttribs()) {
    						boolean ro = i.getAttribute(EFS.ATTRIBUTE_READ_ONLY);
    						p = set(p, IFileSystem.S_IRUSR, i.getAttribute(EFS.ATTRIBUTE_OWNER_READ));
    						p = set(p, IFileSystem.S_IWUSR, !ro && i.getAttribute(EFS.ATTRIBUTE_OWNER_WRITE));
    						p = set(p, IFileSystem.S_IXUSR, i.getAttribute(EFS.ATTRIBUTE_OWNER_EXECUTE));
    						p = set(p, IFileSystem.S_IRGRP, i.getAttribute(EFS.ATTRIBUTE_GROUP_READ));
    						p = set(p, IFileSystem.S_IWGRP, !ro && i.getAttribute(EFS.ATTRIBUTE_GROUP_WRITE));
    						p = set(p, IFileSystem.S_IXGRP, i.getAttribute(EFS.ATTRIBUTE_GROUP_EXECUTE));
    						p = set(p, IFileSystem.S_IROTH, i.getAttribute(EFS.ATTRIBUTE_OTHER_READ));
    						p = set(p, IFileSystem.S_IWOTH, !ro && i.getAttribute(EFS.ATTRIBUTE_OTHER_WRITE));
    						p = set(p, IFileSystem.S_IXOTH, i.getAttribute(EFS.ATTRIBUTE_OTHER_EXECUTE));
    					}
    					if (isSetLastModified()) {
    						mtime = i.getLastModified();
    					}

    					getFileStore().setAttributes(null);
						FileAttrs newAttrs = new FileAttrs(attrs.flags, attrs.size, attrs.uid, attrs.gid,
										p, attrs.atime, mtime, attrs.attributes);
    					fileSystem.setstat(getPath(), newAttrs, new DoneSetStat() {
							@Override
							public void doneSetStat(IToken token, FileSystemException error) {
		    					if (shallAbort(error))
		    						return;
		    					setResult(null);
							}
						});
    				}

					private int set(int p, int flag, boolean set) {
						return set ? p | flag : p & ~flag;
                    }
    			});
    		}
    	});
	}
}

Back to the top