Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import static com.google.common.collect.Lists.newArrayList;

import java.io.File;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -810,7 +811,7 @@ public Answer createVolume(final CreateObjectCommand cmd) {
final SR poolSr = hypervisorResource.getStorageRepository(conn,
CitrixHelper.getSRNameLabel(primaryStore.getUuid(), primaryStore.getPoolType(), primaryStore.getPath()));
VDI.Record vdir = new VDI.Record();
vdir.nameLabel = volume.getName();
vdir.nameLabel = getEncodedVolumeName(volume.getName());
Comment thread
sureshanaparti marked this conversation as resolved.
vdir.SR = poolSr;
vdir.type = Types.VdiType.USER;

Expand All @@ -831,6 +832,26 @@ public Answer createVolume(final CreateObjectCommand cmd) {
}
}

private String getEncodedVolumeName(String volumeName) throws UnsupportedEncodingException {
byte[] utf8Bytes = volumeName.getBytes("UTF-8");
// Decode UTF-8 into a Java String (UTF-16)
String decoded = new String(utf8Bytes, "UTF-8");
// Print each code unit as a Unicode escape
StringBuilder unicodeEscaped = new StringBuilder();
for (int i = 0; i < decoded.length(); i++) {
char ch = decoded.charAt(i);
if (ch <= 127 && Character.isLetterOrDigit(ch)) {
// Keep ASCII alphanumerics as-is
unicodeEscaped.append(ch);
} else {
// Escape non-ASCII characters
unicodeEscaped.append(String.format("\\u%04X", (int) ch));
}
}

return unicodeEscaped.toString();
}

@Override
public Answer cloneVolumeFromBaseTemplate(final CopyCommand cmd) {
final Connection conn = hypervisorResource.getConnection();
Expand Down