Skip to content

Commit 653d325

Browse files
committed
Implement xattr probing behaviour as sugggested by copilot
1 parent 1f7af9c commit 653d325

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

src/openvfsfuse.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -703,19 +703,27 @@ static int openVFSfuse_getxattr(const char *orig_path, const char *name, char *v
703703
return -errno;
704704
}
705705
const auto realSize = std::to_string(statbuf.st_size);
706-
if (realSize.size() < size) {
706+
if (size == 0) {
707+
return static_cast<int>(realSize.size());
708+
} else if (realSize.size() <= size) {
707709
std::ranges::copy(realSize, value);
708710
return static_cast<int>(realSize.size());
709711
}
710712
return -ERANGE;
711713
}
712714
const auto ret = Xattr::getxattr(path, name, value, size);
713715
if (ret == -ENODATA && name == OpenVfsConstants::XAttributeNames::Data) {
716+
errno = 0;
714717
// return the default value for the attributes
715718
// message pack is null terminated
716-
static const auto defaultData = OpenVfsAttributes::PlaceHolderAttributes({}).toData();
717-
if (size > defaultData.size()) {
718-
errno = 0;
719+
static const auto defaultData = [] {
720+
auto data = OpenVfsAttributes::PlaceHolderAttributes({}).toData();
721+
data.push_back('\0');
722+
return data;
723+
}();
724+
if (size == 0) {
725+
return static_cast<int>(defaultData.size());
726+
} else if (defaultData.size() <= size) {
719727
std::ranges::copy(defaultData, value);
720728
openvfsfuse_log(path, "getxattr", 0, "Returning default data for %s: %s", name, value);
721729
return static_cast<int>(defaultData.size());

0 commit comments

Comments
 (0)