Skip to content

Commit

Permalink
fixed 'remote' fs behavior in windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Yshayy committed Oct 15, 2023
1 parent fef27a4 commit 453fbed
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 13 deletions.
6 changes: 3 additions & 3 deletions packages/core/src/commands/up/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,12 @@ const up = async ({
envId,
debug,
tunnelOpts,
sshPrivateKeyPath: path.join(remoteDir, sshPrivateKeyFile.remote),
knownServerPublicKeyPath: path.join(remoteDir, knownServerPublicKey.remote),
sshPrivateKeyPath: path.posix.join(remoteDir, sshPrivateKeyFile.remote),
knownServerPublicKeyPath: path.posix.join(remoteDir, knownServerPublicKey.remote),
user: userAndGroup.join(':'),
machineStatusCommand: await machineDriver.machineStatusCommand(machine),
envMetadata: await envMetadata({ envId, version }),
composeModelPath: path.join(remoteDir, composeModelFilename),
composeModelPath: path.posix.join(remoteDir, composeModelFilename),
privateMode: false,
defaultAccess: 'public',
composeProject: projectName,
Expand Down
13 changes: 7 additions & 6 deletions packages/core/src/compose/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ const volumeSkipList = [
/^\/$/,
]

const toPosix = (x:string) => x.split(path.sep).join(path.posix.sep)

export const fixModelForRemote = async (
{ skipServices = [], cwd, remoteBaseDir }: {
skipServices?: string[]
Expand All @@ -83,20 +85,19 @@ export const fixModelForRemote = async (
if (!path.isAbsolute(absolutePath)) {
throw new Error(`expected absolute path: "${absolutePath}"`)
}

const relativePath = path.relative(cwd, absolutePath)
const relativePath = toPosix(path.relative(cwd, absolutePath))

return relativePath.startsWith('..')
? path.join('absolute', absolutePath)
: path.join('relative', relativePath)
? path.posix.join('absolute', absolutePath)
: path.posix.join('relative', relativePath)
}

const overrideSecretsOrConfigs = (
c?: Record<string, ComposeSecretOrConfig>,
) => mapValues(c ?? {}, secretOrConfig => {
const remote = remotePath(secretOrConfig.file)
filesToCopy.push({ local: secretOrConfig.file, remote })
return { ...secretOrConfig, file: path.join(remoteBaseDir, remote) }
return { ...secretOrConfig, file: path.posix.join(remoteBaseDir, remote) }
})

const overrideSecrets = overrideSecretsOrConfigs(model.secrets)
Expand Down Expand Up @@ -137,7 +138,7 @@ export const fixModelForRemote = async (
filesToCopy.push({ local: volume.source, remote })
}

return { ...volume, source: path.join(remoteBaseDir, remote) }
return { ...volume, source: path.posix.join(remoteBaseDir, remote) }
}, service.volumes)),
})
})
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/remote-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ import path from 'path'

export const REMOTE_DIR_BASE = '/var/lib/preevy'

export const remoteProjectDir = (projectName: string) => path.join(REMOTE_DIR_BASE, 'projects', projectName)
export const remoteProjectDir = (projectName: string) => path.posix.join(REMOTE_DIR_BASE, 'projects', projectName)
2 changes: 1 addition & 1 deletion packages/core/src/ssh/client/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const expandDir = async (local: string | DirInfo | FileInfo) => {
const di = await normalizeDirInfo(local)
const entries = await Promise.all(
// eslint-disable-next-line no-use-before-define
di.entries.map(e => expandFile(isDirEnt(e) ? path.join(di.path, e.name) : e))
di.entries.map(e => expandFile(isDirEnt(e) ? path.posix.join(di.path, e.name) : e))
)

return {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/ssh/client/sftp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export const sftpClient = (
...entries.map(f => self.putFile(
{
local: isDirEnt(f) ? path.join(p, f.name) : f,
remote: path.join(remote, pathFromStringOrFileInfo(f)),
remote: path.posix.join(remote, pathFromStringOrFileInfo(f)),
},
options,
)),
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/upload-files/tar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export const tarStreamer = (initialFilesToCopy: FileToCopy[] = []) => {
},
directoryEntry: (file: FileToCopy, entry: string) => ({
local: path.join(file.local, entry),
remote: path.join(file.remote, entry),
remote: path.posix.join(file.remote, entry),
}),
}

Expand Down

0 comments on commit 453fbed

Please sign in to comment.