WalkPushConnection: Sanitize paths given to transports

These paths are given to the underlying URI-based transports (s3, sftp,
http), all of which expect forward-slash as the path separator
character.

Change-Id: I3cbb5928c9531a4da4691411bd8ac248fdf47ef2
This commit is contained in:
Jeremy T. Braun 2022-12-05 20:38:43 -06:00 committed by Thomas Wolf
parent 61f4a036c6
commit 514ebfdc7e
1 changed files with 13 additions and 4 deletions

View File

@ -230,7 +230,7 @@ private void sendpack(final List<RemoteRefUpdate> updates,
// offsets from appearing to clients.
//
dest.writeInfoPacks(packNames.keySet());
dest.deleteFile(idx.getPath());
dest.deleteFile(sanitizedPath(idx));
}
// Write the pack file, then the index, as readers look the
@ -238,13 +238,13 @@ private void sendpack(final List<RemoteRefUpdate> updates,
//
String wt = "Put " + pack.getName().substring(0, 12); //$NON-NLS-1$
try (OutputStream os = new BufferedOutputStream(
dest.writeFile(pack.getPath(), monitor,
dest.writeFile(sanitizedPath(pack), monitor,
wt + "." + pack.getPackExt().getExtension()))) { //$NON-NLS-1$
writer.writePack(monitor, monitor, os);
}
try (OutputStream os = new BufferedOutputStream(
dest.writeFile(idx.getPath(), monitor,
dest.writeFile(sanitizedPath(idx), monitor,
wt + "." + idx.getPackExt().getExtension()))) { //$NON-NLS-1$
writer.writeIndex(os);
}
@ -269,7 +269,7 @@ private void sendpack(final List<RemoteRefUpdate> updates,
private void safeDelete(File path) {
if (path != null) {
try {
dest.deleteFile(path.getPath());
dest.deleteFile(sanitizedPath(path));
} catch (IOException cleanupFailure) {
// Ignore the deletion failure. We probably are
// already failing and were just trying to pick
@ -366,4 +366,13 @@ private static String pickHEAD(List<RemoteRefUpdate> updates) {
}
return updates.get(0).getRemoteName();
}
private static String sanitizedPath(File file) {
String path = file.getPath();
if (File.separatorChar != '/') {
path = path.replace(File.separatorChar, '/');
}
return path;
}
}