Browse Source

main linux adaptation: mangling of atrtibute names which under linux (only?) require a namespace as prefix

master
Ralf Herold 6 years ago
parent
commit
dc50e55d67
No known key found for this signature in database GPG Key ID: 1D7529BE14E2BBA9
  1. 1
      NAMESPACE
  2. 50
      R/util.R
  3. 18
      man/handle_user_prefix_param.Rd
  4. 18
      man/handle_user_prefix_return.Rd

1
NAMESPACE

@ -16,6 +16,7 @@ export(set_xattr)
importFrom(Rcpp,sourceCpp)
importFrom(magrittr,"%>%")
importFrom(sys,exec_internal)
importFrom(utils,sessionInfo)
importFrom(xml2,as_list)
importFrom(xml2,read_xml)
useDynLib(xattrs)

50
R/util.R

@ -41,3 +41,53 @@ convert_plist <- function(path) {
}
}
# Linux: attributes are prefixed with a namespace, that is,
# an attribute has the form: namespace.attribute
# Examples: user.mime_type, trusted.md5sum, system.posix_acl_access
# for xattrs, the interest is primarily to access the user
# namespace. When a namespace is missing, "user" is used as namespace.
# https://linux.die.net/man/5/attr
#
# Removing the namespace "user" from attribute names used in
# parameters or when listing attributes enables to use the same
# R code across platforms
linux_namespaces <- c("user", "security", "system", "trusted")
#' handle_user_prefix_param
#' @param stringvector vector of strings with attribute names
#' @return stringvector adjusted with required namespace (Linux)
#' @keywords internal
#' @importFrom utils sessionInfo
handle_user_prefix_param <- function(stringvector){
# vectorised function to work on linux where attribute
# name are to be prefixed with "user." for parameters
if(grepl("linux", sessionInfo()$platform)) {
unname(sapply(stringvector, function(x)
ifelse(grepl(paste0("^(", paste0(linux_namespaces, collapse = "|"), ")[.]"), x), x, paste0("user.", x))))
} else {
stringvector
}
}
#' handle_user_prefix_return
#' @param stringvector vector of strings with attribute names
#' @return stringvector adjusted without namespace (Linux)
#' @keywords internal
#' @importFrom utils sessionInfo
handle_user_prefix_return <- function(stringvector){
# vectorised function to work on linux where from
# attribute names the prefix "user." should be removed
if(grepl("linux", sessionInfo()$platform)) {
unname(sapply(stringvector, function(x) ifelse(grepl("^user.", x), sub("^user.(.*)$", "\\1", x))))
} else {
stringvector
}
}

18
man/handle_user_prefix_param.Rd

@ -0,0 +1,18 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/util.R
\name{handle_user_prefix_param}
\alias{handle_user_prefix_param}
\title{handle_user_prefix_param}
\usage{
handle_user_prefix_param(stringvector)
}
\arguments{
\item{stringvector}{vector of strings with attribute names}
}
\value{
stringvector adjusted with required namespace (Linux)
}
\description{
handle_user_prefix_param
}
\keyword{internal}

18
man/handle_user_prefix_return.Rd

@ -0,0 +1,18 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/util.R
\name{handle_user_prefix_return}
\alias{handle_user_prefix_return}
\title{handle_user_prefix_return}
\usage{
handle_user_prefix_return(stringvector)
}
\arguments{
\item{stringvector}{vector of strings with attribute names}
}
\value{
stringvector adjusted without namespace (Linux)
}
\description{
handle_user_prefix_return
}
\keyword{internal}
Loading…
Cancel
Save