fix(workspaces): implement sudo support for rsync to resolve remote permission issues

This commit is contained in:
mkorwel
2026-03-18 12:35:46 -07:00
parent 489b36d5b2
commit fd8755d292
2 changed files with 7 additions and 1 deletions

View File

@@ -71,6 +71,7 @@ export interface ExecOptions {
export interface SyncOptions {
delete?: boolean;
exclude?: string[];
sudo?: boolean;
}
export interface WorkspaceStatus {

View File

@@ -54,13 +54,18 @@ export class GceConnectionManager {
};
}
sync(localPath: string, remotePath: string, options: { delete?: boolean; exclude?: string[] } = {}): number {
sync(localPath: string, remotePath: string, options: { delete?: boolean; exclude?: string[]; sudo?: boolean } = {}): number {
const fullRemote = this.getMagicRemote();
// We use --no-t and --no-perms to avoid "Operation not permitted" errors
// when syncing to volumes that might have UID mismatches with the container.
const rsyncArgs = ['-rvz', '--quiet', '--no-t', '--no-perms', '--no-owner', '--no-group'];
if (options.delete) rsyncArgs.push('--delete');
if (options.exclude) options.exclude.forEach(ex => rsyncArgs.push(`--exclude="${ex}"`));
// Use sudo on the remote side if requested to bypass permission errors
if (options.sudo) {
rsyncArgs.push('--rsync-path="sudo rsync"');
}
const sshCmd = `ssh ${this.getCommonArgs().join(' ')}`;
const directRsync = `rsync ${rsyncArgs.join(' ')} -e ${this.quote(sshCmd)} ${localPath} ${fullRemote}:${remotePath}`;