Re: Post processing scipts not working
Posted: January 26th, 2017, 9:34 am
Thanks for the namei output, ''unfortunately'' it all looks normal. Maybe python and mergerfs just aren't besties...?
Code: Select all
import stat
import time
import os
import sys
def mode_of_file(myfile):
st = os.stat(myfile)
mode, ino, dev, nlink, uid, gid, size, atime, mtime, ctime = st
print oct(mode)
if (int(mode) & 64):
print "Executable"
else:
print "not executable"
try:
mode_of_file(sys.argv[1])
except:
print "Give an existing file or directory as argument"
Code: Select all
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
printf("Hello World. You gave %d arguments.\n", argc);
if (argc<2) {
printf("No file as argument ...");
exit(0);
}
const char *pathname = argv[1];
printf("File %s\n", pathname);
// (R_OK, W_OK, X_OK) or the existence test (F_OK).
printf("F_OK: %d \n", access(pathname, F_OK));
printf("R_OK: %d \n", access(pathname, R_OK));
printf("W_OK: %d \n", access(pathname, W_OK));
printf("X_OK: %d \n", access(pathname, X_OK));
}
Code: Select all
sander@Stream-13:~/test-rwx-bit$ gcc test-f-rwx-bit.c -o test-f-rwx-bit
sander@Stream-13:~/test-rwx-bit$ ./test-f-rwx-bit /bin/bash
Hello World. You gave 2 arguments.
File /bin/bash
F_OK: 0
R_OK: 0
W_OK: -1
X_OK: 0 Code: Select all
0100777
ExecutableCode: Select all
Hello World. You gave 2 arguments.
File /media/Data/downloads/scripts/nzbToMedia/nzbToSickBeard.py
F_OK: 0
R_OK: 0
W_OK: 0
X_OK: -1 Wow ...mcawley wrote:Python code outputc code outputCode: Select all
0100777 ExecutableCode: Select all
Hello World. You gave 2 arguments. File /media/Data/downloads/scripts/nzbToMedia/nzbToSickBeard.py F_OK: 0 R_OK: 0 W_OK: 0 X_OK: -1
That filesystem seems to act as a kind of union of multiple underlying physical hds. Only suggestion I've left is talk to the devs of mergerfs and ask them about the inconsistent results when checking permissions.sander wrote:Or, maybe easier: you put your script on your regular harddisk. Oh wait: /media/Data/downloads/scripts/nzbToMedia/nzbToSickBeard.py is some other disk, isn't it?
Is https://github.com/trapexit/mergerfs the correct source / location?Only suggestion I've left is talk to the devs of mergerfs and ask them about the inconsistent results when checking permissions.
So use os.stat() instead of os.access() as a workaround?So this seems to be a well-known portability problem accross Unix implementations. If you want to test the executable bits, just use os.stat().
Code: Select all
import os
import sys
filename = sys.argv[1]
# one-liner that tells if x-bit is set for user:
print (os.stat(filename)[0] & (1<<6)) > 0
# ... same same, but more clear what's going on:
# rwx rwx rwx
# 876 543 210
userXbit = 1<<6
rwxbits = os.stat(filename)[0]
print (rwxbits & userXbit) > 0
Code: Select all
if not os.access(command[0], os.X_OK):Code: Select all
if not ((os.stat(command[0])[0] & (1<<6)) > 0):Code: Select all
userXbit = 1<<6
rwxbits = os.stat(command[0])[0]
if not ( (rwxbits & userXbit) > 0 ):Code: Select all
if not userxbitisset(command[0]) :Code: Select all
Python script "/home/sander/sab-scripts/noexec.py" does not have execute (+x) permission set
Cannot run script /home/sander/sab-scripts/noexec.pyPR sent: https://github.com/sabnzbd/sabnzbd/pull/800mcawley wrote:New code works perfectly, thank you.