Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mac updates #384

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ ifeq ($(PANDOC),"")
$(warning "pandoc does not appear available: manpage won't be buildable")
endif

XATTR_AVAILABLE = $(shell test ! -e /usr/include/attr/xattr.h; echo $$?)
XATTR_AVAILABLE = $(shell test ! -e /usr/include/attr/xattr.h -a ! -e /usr/include/sys/xattr.h; echo $$?)

FUSE_AVAILABLE = $(shell ! pkg-config --exists fuse; echo $$?)

Expand Down
4 changes: 2 additions & 2 deletions src/fs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ namespace fs
return -1;

dev = st.st_dev;
for(int i = 0, ei = srcmounts.size(); i != ei; i++)
for(size_t i = 0, ei = srcmounts.size(); i != ei; i++)
{
fs::path::make(&srcmounts[i],fusepath,fullpath);

Expand Down Expand Up @@ -241,7 +241,7 @@ namespace fs
if(spaceavail <= mfs)
continue;

mfs = spaceavail;
mfs = (fsblkcnt_t)spaceavail;
mfsbasepath = &basepaths[i];
}

Expand Down
4 changes: 2 additions & 2 deletions src/fs_acl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ namespace fs
bool
dir_has_defaults(const std::string &fullpath)
{
int rv;
ssize_t rv;
std::string dirpath = fullpath;

fs::path::dirname(dirpath);

rv = fs::lgetxattr(dirpath,POSIX_ACL_DEFAULT_XATTR,NULL,0);
rv = fs::lgetxattr(dirpath,POSIX_ACL_DEFAULT_XATTR,NULL,0,0);

return (rv != -1);
}
Expand Down
23 changes: 23 additions & 0 deletions src/fs_base_futimesat.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
ISC License

Copyright (c) 2017, Antonio SJ Musumeci <[email protected]>

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

#if __APPLE__
# include "fs_base_futimesat_osx.icpp"
#else
# include "fs_base_futimesat_generic.icpp"
#endif
30 changes: 30 additions & 0 deletions src/fs_base_futimesat.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
ISC License

Copyright (c) 2017, Antonio SJ Musumeci <[email protected]>

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

#ifndef __FS_BASE_FUTIMESAT_HPP__
#define __FS_BASE_FUTIMESAT_HPP__

namespace fs
{
int
futimesat(const int dirfd,
const char *pathname,
const struct timeval times[2]);
}

#endif
31 changes: 31 additions & 0 deletions src/fs_base_futimesat_generic.icpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
ISC License

Copyright (c) 2017, Antonio SJ Musumeci <[email protected]>

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

#include <fcntl.h>
#include <sys/time.h>

namespace fs
{
int
futimesat(const int dirfd,
const char *pathname,
const struct timeval times[2])
{
return ::futimesat(dirfd,pathname,times);
}
}
83 changes: 83 additions & 0 deletions src/fs_base_futimesat_osx.icpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
ISC License

Copyright (c) 2017, Antonio SJ Musumeci <[email protected]>

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

#include <err.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <sys/errno.h>
#include <sys/param.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <unistd.h>

static
int
getpath(const int dirfd,
const char *path,
char *fullpath)
{
int rv;
struct stat st;

rv = ::fstat(dirfd,&st);
if(rv == -1)
return -1;

if(!S_ISDIR(st.st_mode))
return (errno=ENOTDIR,-1);

rv = ::fcntl(dirfd,F_GETPATH,fullpath);
if(rv == -1)
return -1;

rv = ::strlcat(fullpath,"/",MAXPATHLEN);
if(rv > MAXPATHLEN)
return (errno=ENAMETOOLONG,-1);

rv = ::strlcat(fullpath,path,MAXPATHLEN);
if(rv > MAXPATHLEN)
return (errno=ENAMETOOLONG,-1);

return 0;
}

namespace fs
{
int
futimesat(const int dirfd,
const char *path,
const struct timeval times[2])
{
int rv;
Copy link
Owner

Choose a reason for hiding this comment

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

I'm watching Travis. If I commit something which breaks I'll fix it.

char fullpath[MAXPATHLEN];

if((dirfd == AT_FDCWD) ||
((path != NULL) && (path[0] == '/')))
return ::utimes(path,times);

if(dirfd < 0)
return (errno=EBADF,-1);

rv = getpath(dirfd,path,fullpath);
if(rv == -1)
return -1;

return ::utimes(fullpath,times);
}
}
13 changes: 8 additions & 5 deletions src/fs_base_getxattr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,19 @@ namespace fs
{
static
inline
int
ssize_t
lgetxattr(const std::string &path,
const char *attrname,
void *value,
const size_t size)
const size_t size,
const u_int32_t position)
{
#ifndef WITHOUT_XATTR
return ::lgetxattr(path.c_str(),attrname,value,size);
#else
#if WITHOUT_XATTR
return (errno=ENOTSUP,-1);
#elif __APPLE__
return ::getxattr(path.c_str(),attrname,value,size,position,XATTR_NOFOLLOW);
#else
return ::lgetxattr(path.c_str(),attrname,value,size);
#endif
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/fs_base_ioctl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ namespace fs
static
inline
int
ioctl(const int fd,
const int request,
void *data)
ioctl(const int fd,
const unsigned long request,
void *data)
{
return ::ioctl(fd,request,data);
}
Expand Down
10 changes: 6 additions & 4 deletions src/fs_base_listxattr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,17 @@ namespace fs
{
static
inline
int
ssize_t
llistxattr(const std::string &path,
char *list,
const size_t size)
{
#ifndef WITHOUT_XATTR
return ::llistxattr(path.c_str(),list,size);
#else
#ifdef WITHOUT_XATTR
return (errno=ENOTSUP,-1);
#elif __APPLE__
return ::listxattr(path.c_str(),list,size,XATTR_NOFOLLOW);
#else
return ::llistxattr(path.c_str(),list,size);
#endif
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/fs_base_readlink.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace fs
{
static
inline
int
ssize_t
readlink(const std::string &path,
char *buf,
const size_t bufsiz)
Expand Down
8 changes: 5 additions & 3 deletions src/fs_base_removexattr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ namespace fs
lremovexattr(const std::string &path,
const char *attrname)
{
#ifndef WITHOUT_XATTR
return ::lremovexattr(path.c_str(),attrname);
#else
#if WITHOUT_XATTR
return (errno=ENOTSUP,-1);
#elif __APPLE__
return ::removexattr(path.c_str(),attrname,XATTR_NOFOLLOW);
#else
return ::lremovexattr(path.c_str(),attrname);
#endif
}
}
Expand Down
13 changes: 8 additions & 5 deletions src/fs_base_setxattr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,16 @@ namespace fs
const char *name,
const void *value,
const size_t size,
const int flags)
const int flags,
const u_int32_t position)
{
#ifndef WITHOUT_XATTR
return ::lsetxattr(path.c_str(),name,value,size,flags);
#else
#if WITHOUT_XATTR
return (errno=ENOTSUP,-1);
#endif
#elif __APPLE__
return ::setxattr(path.c_str(),name,value,size,position,flags & XATTR_NOFOLLOW);
Copy link

@briankendall briankendall Apr 13, 2017

Choose a reason for hiding this comment

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

Shouldn't flags & XATTR_NOFOLLOW actually be flags | XATTR_NOFOLLOW? I think using bitwise AND means that it will always be 0 as flags will never have the XATTR_NOFOLLOW bit set, effectively discarding the value of flags.

There's a few other similar places where bitwise AND is used where it probably should be a OR.

Copy link
Owner

Choose a reason for hiding this comment

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

Yup. Should be ORed.

#else
return ::lsetxattr(path.c_str(),name,value,size,flags);
#endif
}
}

Expand Down
50 changes: 50 additions & 0 deletions src/fs_base_stat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,56 @@ namespace fs
{
return ::fstat(fd,&st);
}

static
inline
timespec *
stat_atime(struct stat &st)
{
#if __APPLE__
return &st.st_atimespec;
#else
return &st.st_atim;
#endif
}

static
inline
const
timespec *
stat_atime(const struct stat &st)
{
#if __APPLE__
return &st.st_atimespec;
#else
return &st.st_atim;
#endif
}

static
inline
timespec *
stat_mtime(struct stat &st)
{
#if __APPLE__
return &st.st_mtimespec;
#else
return &st.st_mtim;
#endif
}

static
inline
const
timespec *
stat_mtime(const struct stat &st)
{
#if __APPLE__
return &st.st_mtimespec;
#else
return &st.st_mtim;
#endif
}
}

#endif
Loading