Skip to content
Merged
Show file tree
Hide file tree
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
18 changes: 13 additions & 5 deletions Sources/SWBCore/WorkspaceContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -401,13 +401,21 @@ extension FSProxy {
return try getExtendedAttribute(path, key: Self.CreatedByBuildSystemAttribute) == Self.CreatedByBuildSystemAttributeOnValue
}

/// Sets the "CreatedByBuildSystem" extended attribute on the specified
/// path.
///
/// - Important: The caller is responsible for catching and handling
/// failures if the filesystem does not support extended attributes. Many
/// filesystems (e.g. various non-ext4 temporary filesystems on Linux)
/// don't support xattrs and will return `ENOTSUP`. In particular, tmpfs
/// doesn't support xattrs on Linux unless `CONFIG_TMPFS_XATTR` is enabled
/// in the kernel config.
///
/// - Parameter path: The path on which to set the extended attribute.
/// - Throws: An error if the operation fails, including when the filesystem
/// doesn't support extended attributes.
public func setCreatedByBuildSystemAttribute(_ path: Path) throws {
// Many filesystems on other platforms (e.g. various non-ext4 temporary filesystems on Linux) don't support xattrs and will return ENOTSUP.
// In particular, tmpfs doesn't support xattrs on Linux unless `CONFIG_TMPFS_XATTR` is enabled in the kernel config.
// FIXME: Detect whether the FS supports xattrs at runtime
#if canImport(Darwin)
try setExtendedAttribute(path, key: Self.CreatedByBuildSystemAttribute, value: Self.CreatedByBuildSystemAttributeOnValue)
#endif
}

public func commandLineArgumentsToApplyCreatedByBuildSystemAttribute(to path: Path) -> [String] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,22 @@ public final class CreateBuildDirectoryTaskAction: TaskAction {

do {
try fs.createDirectory(directoryPath, recursive: true)
try fs.setCreatedByBuildSystemAttribute(directoryPath)
return .succeeded
} catch {
outputDelegate?.emitError(error.localizedDescription)
return .failed
}

// Warn on Darwin if we are unable to set the "CreatedByBuildSystem"
// attribute
do {
try fs.setCreatedByBuildSystemAttribute(directoryPath)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other alternative is we just use try? and drop the diagnostic entirely. @owenv, what do you think?

The reason I suggested the if-Darwin to @rauhul is because we'd otherwise have to change tests to ignore this message since most Linux build environments are using containers, which use tmpfs, which don't support xattrs.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the xattr still control whether we're willing to clean a directory? If yes, it could be quite confusing that we never told the user about the fact that we couldn't set it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a setting to allow deleting directories without the attr, but I think this warning still makes sense

} catch {
#if canImport(Darwin)
outputDelegate?.emitWarning("Failed to set build system attribute on \(directoryPath.str): \(error.localizedDescription)")
#endif
}

return .succeeded
}

public override func performTaskAction(
Expand Down