MCPcopy Create free account
hub / github.com/RedisGears/RedisGears / PythonRequirementCtx_Serialize

Function PythonRequirementCtx_Serialize

plugins/python/redisgears_python.c:623–670  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

621}
622
623static int PythonRequirementCtx_Serialize(PythonRequirementCtx* req, Gears_BufferWriter* bw, char** err){
624 if(!req->isDownloaded){
625 // requirement is not downloaded yet and so we can not serialized it
626 // this can only happened if rdb save was trigger before download
627 // completed. In this case rdb will not contains this requirement.
628 // It will succeded next time.
629 *err = RG_STRDUP("Requirement was not installed yet");
630 return REDISMODULE_ERR;
631 }
632 RedisGears_BWWriteString(bw, req->installName);
633 RedisGears_BWWriteString(bw, RedisGears_GetCompiledOs());
634 RedisGears_BWWriteLong(bw, req->isInRequirementsDict);
635 RedisGears_BWWriteLong(bw, array_len(req->wheels));
636 for(size_t i = 0 ; i < array_len(req->wheels) ; ++i){
637 char* wheel = req->wheels[i];
638 char* filePath;
639 RedisGears_ASprintf(&filePath, "%s/%s", req->basePath, wheel);
640
641 FILE *f = fopen(filePath, "rb");
642 if(!f){
643 RedisGears_ASprintf(err, "Could not open file %s", filePath);
644 RG_FREE(filePath);
645 RedisModule_Log(staticCtx, "warning", "%s", *err);
646 return REDISMODULE_ERR;
647 }
648 fseek(f, 0, SEEK_END);
649 long fsize = ftell(f);
650 fseek(f, 0, SEEK_SET); /* same as rewind(f); */
651
652 char *data = RG_ALLOC(fsize);
653 size_t readData = fread(data, 1, fsize, f);
654 if(readData != fsize){
655 RedisGears_ASprintf(err, "Could read data from file %s", filePath);
656 RG_FREE(data);
657 RG_FREE(filePath);
658 RedisModule_Log(staticCtx, "warning", "%s", *err);
659 return REDISMODULE_ERR;
660 }
661 fclose(f);
662
663 RedisGears_BWWriteString(bw, wheel);
664 RedisGears_BWWriteBuffer(bw, data, fsize);
665
666 RG_FREE(data);
667 RG_FREE(filePath);
668 }
669 return REDISMODULE_OK;
670}
671
672static int PythonRequirement_Serialize(PythonRequirementCtx* req, Gears_BufferWriter* bw, char** err){
673 RedisGears_BWWriteLong(bw, PY_REQ_VERSION);

Calls 1

array_lenFunction · 0.85

Tested by

no test coverage detected