Skip to content

Commit

Permalink
Add the functionality to download folder content.
Browse files Browse the repository at this point in the history
Signed-off-by: Akayeshmantha <[email protected]>
  • Loading branch information
Akayeshmantha committed Aug 5, 2020
1 parent 5aa17c2 commit c6e9a7a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
35 changes: 35 additions & 0 deletions c/unixFileService.c
Original file line number Diff line number Diff line change
Expand Up @@ -981,6 +981,26 @@ static int serveUnixFileChangeOwner (HttpService *service, HttpResponse *respons
return 0;
}

static int serveUnixFolderDownloadMode(HttpService *service, HttpResponse *response) {
HttpRequest *request = response->request;
char *routeFileFrag = stringListPrint(request->parsedFile, 2, 1000, "/", 0);

if (routeFileFrag == NULL || strlen(routeFileFrag) == 0) {
respondWithJsonError(response, "Required absolute path of the resource is not provided", HTTP_STATUS_BAD_REQUEST, "Bad Request");
return 0;
}
char *encodedRouteFolder = stringConcatenate(response->slh, "/", routeFileFrag);
char *routeFolderName = cleanURLParamValue(response->slh, encodedRouteFolder);

if (!strcmp(request->method, methodGET)) {
createFileFromUnixDirectoryAndRespond (response, routeFolderName);
}
else {
respondWithJsonError(response, "Method Not Allowed", HTTP_STATUS_METHOD_NOT_FOUND, "Bad Request");
return 0;
}
return 0;
}

static int serveTableOfContents(HttpService *service, HttpResponse *response) {
HttpRequest *request = response->request;
Expand Down Expand Up @@ -1023,6 +1043,10 @@ static int serveTableOfContents(HttpService *service, HttpResponse *response) {
jsonAddString(out, "chmod", "/unixfile/chmod/{absPath}");
jsonEndObject(out);

jsonStartObject(out, NULL);
jsonAddString(out, "folderdownload", "/unixfile/folderdownload/{absPath}");
jsonEndObject(out);

jsonEndArray(out);
jsonEnd(out);

Expand Down Expand Up @@ -1144,6 +1168,17 @@ void installUnixFileTableOfContentsService(HttpServer *server) {
registerHttpService(server, httpService);
}

void installUnixFolderToFileConvertAndDownloadService(HttpServer *server) {
HttpService *httpService = makeGeneratedService("UnixFolderDownload",
"/unixfile/folderdownload/**");
httpService->authType = SERVICE_AUTH_NATIVE_WITH_SESSION_TOKEN;
httpService->serviceFunction = serveUnixFolderDownloadMode;
httpService->runInSubtask = TRUE;
httpService->doImpersonation = TRUE;
registerHttpService(server, httpService);
}



/*
This program and the accompanying materials are
Expand Down
1 change: 1 addition & 0 deletions c/zss.c
Original file line number Diff line number Diff line change
Expand Up @@ -1216,6 +1216,7 @@ int main(int argc, char **argv){
installUnixFileMetadataService(server);
installUnixFileChangeOwnerService(server);
installUnixFileChangeModeService(server);
installUnixFolderToFileConvertAndDownloadService(server);
installUnixFileTableOfContentsService(server); /* This needs to be registered last */
#ifdef __ZOWE_OS_ZOS
installVSAMDatasetContentsService(server);
Expand Down
1 change: 1 addition & 0 deletions h/unixFileService.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ void installUnixFileMetadataService(HttpServer *server);
void installUnixFileChangeOwnerService(HttpServer *server);
void installUnixFileTableOfContentsService(HttpServer *server);
void installUnixFileChangeModeService(HttpServer *server);
void installUnixFolderToFileConvertAndDownloadService(HttpServer *server);

#endif

Expand Down

0 comments on commit c6e9a7a

Please sign in to comment.