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

Unix file metatadata #381

Open
wants to merge 5 commits into
base: v1.x/staging
Choose a base branch
from
Open
Changes from all 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
58 changes: 56 additions & 2 deletions mock/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,20 @@ def genVolserId():
global_directory = {
"permissions": 777,
"type": "folder",
"createdAt": "1999-06-02T12:35:07",
"ccsid": 37,
"contents": {
"folder1": {
"permissions": 777,
"type": "folder",
"createdAt": "1998-08-02T17:49:22",
"ccsid": 37,
"contents": {
"file1": {
"permissions": 777,
"type": "file",
"createdAt": "2021-06-02T12:35:07",
"ccsid": 37,
"contents": {
"raw": "This is file1",
"b64": "VGhpcyBpcyBmaWxlMQ=="
Expand All @@ -119,10 +125,14 @@ def genVolserId():
"folderA": {
"permissions": 777,
"type": "folder",
"createdAt": "2021-10-03T09:55:24",
"ccsid": 37,
"contents": {
"fileA": {
"permissions": 777,
"type": "file",
"createdAt": "2021-10-03T09:55:24",
"ccsid": 37,
"contents": {
"raw": "This is fileA",
"b64": "VGhpcyBpcyBmaWxlQQ=="
Expand All @@ -135,11 +145,15 @@ def genVolserId():
"folder2": {
"permissions": 777,
"type": "folder",
"createdAt": "2021-10-03T09:55:24",
"ccsid": 37,
"contents": {}
},
"file1": {
"permissions": 777,
"type": "file",
"createdAt": "2021-10-03T09:55:24",
"ccsid": 37,
"contents": {
"raw": "This is file1",
"b64": "VGhpcyBpcyBmaWxlMQ=="
Expand All @@ -148,6 +162,8 @@ def genVolserId():
"file2": {
"permissions": 777,
"type": "file",
"createdAt": "2021-10-03T09:55:24",
"ccsid": 37,
"contents": {
"raw": "Goodbye",
"b64": "VGhpcyBpcyBmaWxlMg=="
Expand All @@ -156,6 +172,8 @@ def genVolserId():
"noPermissions": {
"permissions": 0,
"type": "file",
"createdAt": "2021-10-03T09:55:24",
"ccsid": 37,
"contents": {
"raw": "You should not be able to read this",
"b64": "WW91IHNob3VsZCBub3QgYmUgYWJsZSB0byByZWFkIHRoaXM="
Expand Down Expand Up @@ -206,7 +224,7 @@ def unix_contents(subpath):
"directory": True if global_directory['contents'][key]['type'] == "folder" else False,
"size": 9,
"ccsid": 0,
"createdAt": "2018-11-03T14:18:27",
"createdAt": global_directory['contents'][key]['createdAt'],
"mode": 777
}
)
Expand All @@ -230,7 +248,7 @@ def unix_contents(subpath):
"directory": True if directory['contents'][key]['type'] == "folder" else False,
"size": 9,
"ccsid": 0,
"createdAt": "2018-11-03T14:18:27",
"createdAt": directory['contents'][key]['createdAt'],
"mode": 777
}
)
Expand Down Expand Up @@ -535,6 +553,42 @@ def unixfile_copy(subpath):
dir = dir["contents"][newNames[i]]
return {"msg": "File Successfully Copied"}

@app.route('/unixfile/metaData/<path:subpath>', methods=['GET'])
def unixfile_metaData(subpath):
if request.method == 'GET':
directory = global_directory["contents"]
metaData = {
"path": subpath,
"directory": True,
"size": 0,
"ccsid": 0,
"createdAt": "",
"mode": 0
}
if(subpath is None or subpath == ""):
return {'error': 'File/Directory could not be opened or does not exist.'}, 404
subpath = subpath.split("/")
currPath = directory
#Go to the folder above the final dest and return if the path DNE
for x in range(0, len(subpath)-1):
if (subpath[x] not in currPath):
return {'error': 'File/Directory could not be opened or does not exist.'}, 404
currPath = currPath[subpath[x]]["contents"]
dest = subpath[len(subpath)-1]
#Check if the dest is in the final path and return if the path DNE
if (dest not in currPath):
return {'error': 'File/Directory could not be opened or does not exist.'}, 404
currPath = currPath[dest]
metaData["size"] = len(currPath["contents"])
#Set the file specific metadata
if(currPath["type"] == "file"):
metaData["directory"] = False
metaData["size"] = len(currPath["contents"]["raw"])
metaData["mode"] = currPath["permissions"]
metaData["createdAt"] = currPath["createdAt"]
metaData["ccsid"] = currPath["ccsid"]
return metaData, 200

if __name__ == '__main__':
app.run(debug=True)