diff --git a/src/access.cpp b/src/access.cpp index 0378d5c6..4a8f924d 100644 --- a/src/access.cpp +++ b/src/access.cpp @@ -1,33 +1,27 @@ /* - The MIT License (MIT) - - Copyright (c) 2014 Antonio SJ Musumeci - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. + The MIT License (MIT) + + Copyright (c) 2016 Antonio SJ Musumeci + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE -#endif - -#include - #include #include @@ -53,15 +47,15 @@ _access(Policy::Func::Search searchFunc, const int mask) { int rv; - vector path; + string path; rv = searchFunc(srcmounts,fusepath,minfreespace,path); if(rv == -1) return -errno; - fs::path::append(path[0],fusepath); + fs::path::append(path,fusepath); - rv = ::eaccess(path[0].c_str(),mask); + rv = ::eaccess(path.c_str(),mask); return ((rv == -1) ? -errno : 0); } diff --git a/src/chmod.cpp b/src/chmod.cpp index f9988993..004bac17 100644 --- a/src/chmod.cpp +++ b/src/chmod.cpp @@ -1,25 +1,25 @@ /* - The MIT License (MIT) - - Copyright (c) 2014 Antonio SJ Musumeci - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. + The MIT License (MIT) + + Copyright (c) 2016 Antonio SJ Musumeci + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ #include @@ -30,6 +30,7 @@ #include "config.hpp" #include "fs_path.hpp" +#include "rv.hpp" #include "rwlock.hpp" #include "ugid.hpp" @@ -53,14 +54,14 @@ _chmod(Policy::Func::Action actionFunc, if(rv == -1) return -errno; - error = 0; + error = -1; for(size_t i = 0, ei = paths.size(); i != ei; i++) { fs::path::append(paths[i],fusepath); rv = ::chmod(paths[i].c_str(),mode); - if(rv == -1) - error = errno; + + error = calc_error(rv,error,errno); } return -error; diff --git a/src/chown.cpp b/src/chown.cpp index afaa3381..a9d7eefe 100644 --- a/src/chown.cpp +++ b/src/chown.cpp @@ -1,25 +1,25 @@ /* - The MIT License (MIT) - - Copyright (c) 2014 Antonio SJ Musumeci - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. + The MIT License (MIT) + + Copyright (c) 2016 Antonio SJ Musumeci + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ #include @@ -31,6 +31,7 @@ #include "config.hpp" #include "fs_path.hpp" +#include "rv.hpp" #include "rwlock.hpp" #include "ugid.hpp" @@ -56,14 +57,14 @@ _chown(Policy::Func::Action actionFunc, if(rv == -1) return -errno; - error = 0; + error = -1; for(size_t i = 0, ei = paths.size(); i != ei; i++) { fs::path::append(paths[i],fusepath); rv = ::lchown(paths[i].c_str(),uid,gid); - if(rv == -1) - error = errno; + + error = calc_error(rv,error,errno); } return -error; diff --git a/src/link.cpp b/src/link.cpp index fad4df11..bdb92ec2 100644 --- a/src/link.cpp +++ b/src/link.cpp @@ -1,25 +1,25 @@ /* - The MIT License (MIT) - - Copyright (c) 2014 Antonio SJ Musumeci - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. + The MIT License (MIT) + + Copyright (c) 2016 Antonio SJ Musumeci + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ #include @@ -33,6 +33,7 @@ #include "config.hpp" #include "fs_clonepath.hpp" #include "fs_path.hpp" +#include "rv.hpp" #include "rwlock.hpp" #include "ugid.hpp" @@ -55,7 +56,7 @@ _single_link(Policy::Func::Search searchFunc, const string fullnewpath = fs::path::make(base,newpath); rv = ::link(fulloldpath.c_str(),fullnewpath.c_str()); - if(rv == -1 && errno == ENOENT) + if((rv == -1) && (errno == ENOENT)) { string newpathdir; vector foundpath; @@ -93,12 +94,12 @@ _link(Policy::Func::Search searchFunc, if(rv == -1) return -errno; - error = 0; + error = -1; for(size_t i = 0, ei = oldpaths.size(); i != ei; i++) { rv = _single_link(searchFunc,srcmounts,minfreespace,oldpaths[i],oldpath,newpath); - if(rv == -1) - error = errno; + + error = calc_error(rv,error,errno); } return -error; diff --git a/src/mkdir.cpp b/src/mkdir.cpp index 07b1f0ff..40da0082 100644 --- a/src/mkdir.cpp +++ b/src/mkdir.cpp @@ -1,25 +1,25 @@ /* - The MIT License (MIT) - - Copyright (c) 2014 Antonio SJ Musumeci - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. + The MIT License (MIT) + + Copyright (c) 2016 Antonio SJ Musumeci + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ #include @@ -34,6 +34,7 @@ #include "config.hpp" #include "fs_clonepath.hpp" #include "fs_path.hpp" +#include "rv.hpp" #include "rwlock.hpp" #include "ugid.hpp" @@ -67,7 +68,7 @@ _mkdir(Policy::Func::Search searchFunc, if(rv == -1) return -errno; - error = 0; + error = -1; for(size_t i = 0, ei = createpaths.size(); i != ei; i++) { string &createpath = createpaths[i]; @@ -81,8 +82,8 @@ _mkdir(Policy::Func::Search searchFunc, fs::path::append(createpath,fusepath); rv = ::mkdir(createpath.c_str(),mode); - if(rv == -1) - error = errno; + + error = calc_error(rv,error,errno); } return -error; diff --git a/src/mknod.cpp b/src/mknod.cpp index f7e69f48..d30c8e0c 100644 --- a/src/mknod.cpp +++ b/src/mknod.cpp @@ -1,25 +1,25 @@ /* - The MIT License (MIT) - - Copyright (c) 2014 Antonio SJ Musumeci - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. + The MIT License (MIT) + + Copyright (c) 2016 Antonio SJ Musumeci + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ #include @@ -36,6 +36,7 @@ #include "config.hpp" #include "fs_clonepath.hpp" #include "fs_path.hpp" +#include "rv.hpp" #include "rwlock.hpp" #include "ugid.hpp" @@ -68,7 +69,7 @@ _mknod(Policy::Func::Search searchFunc, if(rv == -1) return -errno; - error = 0; + error = -1; for(size_t i = 0, ei = createpaths.size(); i != ei; i++) { string &createpath = createpaths[0]; @@ -82,8 +83,8 @@ _mknod(Policy::Func::Search searchFunc, fs::path::append(createpath,fusepath); rv = ::mknod(createpath.c_str(),mode,dev); - if(rv == -1) - error = errno; + + error = calc_error(rv,error,errno); } return -error; diff --git a/src/removexattr.cpp b/src/removexattr.cpp index 955b6e16..c1b1e3d4 100644 --- a/src/removexattr.cpp +++ b/src/removexattr.cpp @@ -1,25 +1,25 @@ /* - The MIT License (MIT) - - Copyright (c) 2014 Antonio SJ Musumeci - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. + The MIT License (MIT) + + Copyright (c) 2016 Antonio SJ Musumeci + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ #include @@ -32,6 +32,7 @@ #include "config.hpp" #include "fs_path.hpp" +#include "rv.hpp" #include "rwlock.hpp" #include "ugid.hpp" #include "xattr.hpp" @@ -57,14 +58,14 @@ _removexattr(Policy::Func::Action actionFunc, if(rv == -1) return -errno; - error = 0; + error = -1; for(size_t i = 0, ei = paths.size(); i != ei; i++) { fs::path::append(paths[i],fusepath); rv = ::lremovexattr(paths[i].c_str(),attrname); - if(rv == -1) - error = errno; + + error = calc_error(rv,error,errno); } return -error; diff --git a/src/rename.cpp b/src/rename.cpp index ac8a9b5e..25228dd6 100644 --- a/src/rename.cpp +++ b/src/rename.cpp @@ -34,6 +34,7 @@ #include "config.hpp" #include "fs_clonepath.hpp" #include "fs_path.hpp" +#include "rv.hpp" #include "rwlock.hpp" #include "ugid.hpp" @@ -51,23 +52,6 @@ member(const vector &haystack, return (std::find(haystack.begin(),haystack.end(),needle) != haystack.end()); } -// a single success trumps any failure -static -int -_process_rv(const int rv, - const int preverror, - const int error) -{ - if(rv == -1) - { - if(preverror == 0) - return 0; - return error; - } - - return 0; -} - static void _remove(const vector &toremove) @@ -106,7 +90,7 @@ _rename_create_path_one(const vector &oldbasepaths, fs::path::make(oldbasepath,oldfusepath,oldfullpath); rv = ::rename(oldfullpath.c_str(),newfullpath.c_str()); - error = _process_rv(rv,error,errno); + error = calc_error(rv,error,errno); if(rv == -1) tounlink.push_back(oldfullpath); } @@ -231,7 +215,7 @@ _rename_preserve_path_one(Policy::Func::Search searchFunc, rv = ::rename(oldfullpath.c_str(),newfullpath.c_str()); } - error = _process_rv(rv,error,errno); + error = calc_error(rv,error,errno); if(rv == -1) toremove.push_back(oldfullpath); } diff --git a/src/rmdir.cpp b/src/rmdir.cpp index 208ba817..b98bbc87 100644 --- a/src/rmdir.cpp +++ b/src/rmdir.cpp @@ -1,25 +1,25 @@ /* - The MIT License (MIT) - - Copyright (c) 2014 Antonio SJ Musumeci - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. + The MIT License (MIT) + + Copyright (c) 2016 Antonio SJ Musumeci + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ #include @@ -31,6 +31,7 @@ #include "config.hpp" #include "fs_path.hpp" +#include "rv.hpp" #include "rwlock.hpp" #include "ugid.hpp" @@ -53,14 +54,14 @@ _rmdir(Policy::Func::Action actionFunc, if(rv == -1) return -errno; - error = 0; + error = -1; for(size_t i = 0, ei = paths.size(); i != ei; i++) { fs::path::append(paths[i],fusepath); rv = ::rmdir(paths[i].c_str()); - if(rv == -1) - error = errno; + + error = calc_error(rv,error,errno); } return -error; diff --git a/src/rv.hpp b/src/rv.hpp new file mode 100644 index 00000000..abecd9c7 --- /dev/null +++ b/src/rv.hpp @@ -0,0 +1,45 @@ +/* + The MIT License (MIT) + + Copyright (c) 2016 Antonio SJ Musumeci + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. +*/ + +#ifndef __RV_HPP__ +#define __RV_HPP__ + +static +inline +int +calc_error(const int rv, + const int prev, + const int cur) +{ + if(rv == -1) + { + if(prev == 0) + return 0; + return cur; + } + + return 0; +} + +#endif // __RV_HPP__ diff --git a/src/setxattr.cpp b/src/setxattr.cpp index ec2ffe0e..9458114d 100644 --- a/src/setxattr.cpp +++ b/src/setxattr.cpp @@ -1,25 +1,25 @@ /* - The MIT License (MIT) - - Copyright (c) 2014 Antonio SJ Musumeci - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. + The MIT License (MIT) + + Copyright (c) 2016 Antonio SJ Musumeci + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ #include @@ -35,6 +35,7 @@ #include "config.hpp" #include "fs_path.hpp" #include "num.hpp" +#include "rv.hpp" #include "rwlock.hpp" #include "str.hpp" #include "ugid.hpp" @@ -314,14 +315,14 @@ _setxattr(Policy::Func::Action actionFunc, if(rv == -1) return -errno; - error = 0; + error = -1; for(size_t i = 0, ei = paths.size(); i != ei; i++) { fs::path::append(paths[i],fusepath); rv = ::lsetxattr(paths[i].c_str(),attrname,attrval,attrvalsize,flags); - if(rv == -1) - error = errno; + + error = calc_error(rv,error,errno); } return -error; diff --git a/src/symlink.cpp b/src/symlink.cpp index e21c338c..845b5f5c 100644 --- a/src/symlink.cpp +++ b/src/symlink.cpp @@ -1,25 +1,25 @@ /* - The MIT License (MIT) - - Copyright (c) 2014 Antonio SJ Musumeci - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. + The MIT License (MIT) + + Copyright (c) 2014 Antonio SJ Musumeci + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ #include @@ -31,6 +31,7 @@ #include "config.hpp" #include "fs_path.hpp" +#include "rv.hpp" #include "rwlock.hpp" #include "ugid.hpp" @@ -56,14 +57,14 @@ _symlink(Policy::Func::Create createFunc, if(rv == -1) return -errno; - error = 0; + error = -1; for(size_t i = 0, ei = newpathdirs.size(); i != ei; i++) { fs::path::append(newpathdirs[i],newpath); rv = symlink(oldpath.c_str(),newpathdirs[i].c_str()); - if(rv == -1) - error = errno; + + error = calc_error(rv,error,errno); } return -error; diff --git a/src/truncate.cpp b/src/truncate.cpp index 2d81ec29..7b484b0f 100644 --- a/src/truncate.cpp +++ b/src/truncate.cpp @@ -1,25 +1,25 @@ /* - The MIT License (MIT) - - Copyright (c) 2014 Antonio SJ Musumeci - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. + The MIT License (MIT) + + Copyright (c) 2016 Antonio SJ Musumeci + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ #include @@ -33,6 +33,7 @@ #include "config.hpp" #include "fs_path.hpp" +#include "rv.hpp" #include "rwlock.hpp" #include "ugid.hpp" @@ -56,14 +57,14 @@ _truncate(Policy::Func::Action actionFunc, if(rv == -1) return -errno; - error = 0; + error = -1; for(size_t i = 0, ei = paths.size(); i != ei; i++) { fs::path::append(paths[i],fusepath); rv = ::truncate(paths[i].c_str(),size); - if(rv == -1) - error = errno; + + error = calc_error(rv,error,errno); } return -error; diff --git a/src/unlink.cpp b/src/unlink.cpp index 7c4cdd5f..6ac2e7dd 100644 --- a/src/unlink.cpp +++ b/src/unlink.cpp @@ -1,25 +1,25 @@ /* - The MIT License (MIT) - - Copyright (c) 2014 Antonio SJ Musumeci - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. + The MIT License (MIT) + + Copyright (c) 2014 Antonio SJ Musumeci + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ #include @@ -32,6 +32,7 @@ #include "config.hpp" #include "fs_path.hpp" +#include "rv.hpp" #include "rwlock.hpp" #include "ugid.hpp" @@ -54,14 +55,14 @@ _unlink(Policy::Func::Action actionFunc, if(rv == -1) return -errno; - error = 0; + error = -1; for(size_t i = 0, ei = paths.size(); i != ei; i++) { fs::path::append(paths[i],fusepath); rv = ::unlink(paths[i].c_str()); - if(rv == -1) - error = errno; + + error = calc_error(rv,error,errno); } return -error; diff --git a/src/utimens.cpp b/src/utimens.cpp index 47317b8e..d54ebf1d 100644 --- a/src/utimens.cpp +++ b/src/utimens.cpp @@ -1,25 +1,25 @@ /* - The MIT License (MIT) - - Copyright (c) 2014 Antonio SJ Musumeci - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. + The MIT License (MIT) + + Copyright (c) 2016 Antonio SJ Musumeci + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ #include @@ -33,6 +33,7 @@ #include "config.hpp" #include "fs_path.hpp" +#include "rv.hpp" #include "rwlock.hpp" #include "ugid.hpp" @@ -56,14 +57,14 @@ _utimens(Policy::Func::Action actionFunc, if(rv == -1) return -errno; - error = 0; + error = -1; for(size_t i = 0, ei = paths.size(); i != ei; i++) { fs::path::append(paths[i],fusepath); rv = ::utimensat(0,paths[i].c_str(),ts,AT_SYMLINK_NOFOLLOW); - if(rv == -1) - error = errno; + + error = calc_error(rv,error,errno); } return -error;