Comments
This commit is contained in:
parent
87f3ea2900
commit
5ffd8c6551
|
@ -173,10 +173,12 @@ class ufps:
|
|||
"""
|
||||
realpath = self.basedir+path
|
||||
|
||||
# Get file user id and group id
|
||||
stats = os.stat(realpath)
|
||||
uid = stats.st_uid
|
||||
gid = stats.st_gid
|
||||
|
||||
# Turn the funny numbers we just got into names.
|
||||
ownername = pwd.getpwuid(stats.st_uid).pw_name
|
||||
groupname = grp.getgrgid(stats.st_gid).gr_name
|
||||
|
||||
|
@ -206,18 +208,24 @@ class ufps:
|
|||
outputIndex = ""
|
||||
|
||||
realpath = self.basedir+path
|
||||
# The magic prinf sauce makes it so the command returns only relative paths.
|
||||
# For example: test/testdir instead of ./path/to/test/testdir
|
||||
findCommand = "find " + realpath + " -printf '%P\n'"
|
||||
|
||||
# Run the find command and turn it into a list.
|
||||
fileList = subprocess.check_output(findCommand, shell=True, text=True)
|
||||
fileList = fileList.split('\n')
|
||||
|
||||
# Remove tailing newline which causes the root directory to be indexed twice.
|
||||
fileList = fileList[:-1]
|
||||
|
||||
# For every item in the list, we get it's permissions and owner/group info.
|
||||
for p in fileList:
|
||||
pPerms, pIsDir, pIsLink, pLinkTarget = self.getFilePermissions(p)
|
||||
ownername, groupname = self.getFileOwner(p)
|
||||
|
||||
# Stanardized table entry for ufps indexes.
|
||||
# Future additions get added to the end.
|
||||
D_userFriendlyString = pPerms + " | " + ownername + " | " + groupname + " | " + str(pIsDir) + " | " + str(pIsLink) + " | " + p + " | " + str(pLinkTarget) + "\n"
|
||||
outputIndex+=D_userFriendlyString
|
||||
|
||||
|
@ -239,20 +247,28 @@ class ufps:
|
|||
:rtype results: str
|
||||
"""
|
||||
realpath = self.basedir+path
|
||||
print(realpath)
|
||||
results = ""
|
||||
|
||||
# Read index file into variable and split it into an array.
|
||||
# At this point, we have a variable that's exactly the same as it was at the
|
||||
# time of index creation.
|
||||
file = open(index)
|
||||
idx = file.read()
|
||||
file.close()
|
||||
|
||||
idx = idx.split('\n')
|
||||
for p in idx:
|
||||
indexEntry = p.split(' | ')
|
||||
print(indexEntry)
|
||||
indexRealPath = realpath + indexEntry[self.I_IPATH]
|
||||
permsToSet = int(indexEntry[self.I_PERMS], base=8)
|
||||
pathExists = os.path.exists(indexRealPath)
|
||||
|
||||
# For every entry in the index...
|
||||
for p in idx:
|
||||
# Split the entry into a list.
|
||||
indexEntry = p.split(' | ')
|
||||
|
||||
# Then get the real path of the indexed file, figure out if it exists,
|
||||
# and get the entry's permissions.
|
||||
indexRealPath = realpath + indexEntry[self.I_IPATH]
|
||||
pathExists = os.path.exists(indexRealPath)
|
||||
permsToSet = int(indexEntry[self.I_PERMS], base=8)
|
||||
|
||||
# If the path doesn't exist, we log this. Otherwise, set the permissions.
|
||||
if pathExists:
|
||||
os.chmod(indexRealPath, permsToSet)
|
||||
else:
|
||||
|
|
Loading…
Reference in a new issue