Changeset 886 for branches/prototype-v0/zoo-project/zoo-kernel/sshapi.c
- Timestamp:
- Oct 11, 2018, 4:30:46 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/prototype-v0/zoo-project/zoo-kernel/sshapi.c
r877 r886 438 438 } 439 439 if(!sessions[cnt]->sftp_session) 440 zSleep(1 0);440 zSleep(1); 441 441 } while (!sessions[cnt]->sftp_session); 442 442 do { … … 453 453 } 454 454 if(!sftp_handle) 455 zSleep(1 00);455 zSleep(1); 456 456 } while (!sftp_handle); 457 457 … … 530 530 char *logPath=(char*)malloc((strlen(tmpPath->value)+strlen(uuid->value)+11)*sizeof(char)); 531 531 sprintf(logPath,"%s/exec_out_%s",tmpPath->value,uuid->value); 532 532 533 FILE* logFile=fopen(logPath,"wb"); 533 534 free(logPath); … … 542 543 bytecount += rc; 543 544 buffer[rc]=0; 545 544 546 fprintf(logFile,"%s",buffer); 545 547 fflush(logFile); … … 649 651 } 650 652 653 int fileMd5Check(maps** conf,const char* localPath,const char* targetPath){ 654 if(strstr(localPath,".zca")!=NULL){ 655 char *logPath=NULL; 656 char *command=(char*)malloc((strlen(targetPath)+27)*sizeof(char)); 657 sprintf(command,"md5sum %s | awk {'print $1'}",targetPath); 658 if(ssh_exec(*conf,command,ssh_get_cnt(*conf))<=0){ 659 return -1; 660 }else{ 661 struct stat f_status={}; 662 map* usid=getMapFromMaps(*conf,"lenv","usid"); 663 map* tmpMap=getMapFromMaps(*conf,"main","tmpPath"); 664 char* tmpPath=zStrdup(localPath); 665 tmpPath[strlen(tmpPath)-2]='m'; 666 tmpPath[strlen(tmpPath)-1]='d'; 667 free(command); 668 logPath=(char*)malloc((strlen(tmpMap->value)+strlen(usid->value)+11)*sizeof(char)); 669 sprintf(logPath,"%s/exec_out_%s",tmpMap->value,usid->value); 670 int ts=stat(logPath, &f_status); 671 if(ts==0) { 672 char* fcontent=(char*)malloc(sizeof(char)*(f_status.st_size+1)); 673 FILE* f=fopen(logPath,"rb"); 674 fread(fcontent,f_status.st_size,1,f); 675 fcontent[f_status.st_size-1]=0; 676 fclose(f); 677 free(logPath); 678 struct stat f_status1={}; 679 int ts1=stat(tmpPath, &f_status1); 680 if(ts1==0) { 681 char* fcontent1=(char*)malloc(sizeof(char)*(f_status.st_size+1)); 682 FILE* f1=fopen(tmpPath,"rb"); 683 fread(fcontent1,f_status1.st_size,1,f1); 684 fcontent1[f_status1.st_size]=0; 685 fclose(f1); 686 free(tmpPath); 687 if(strcmp(fcontent,fcontent1)==0){ 688 free(fcontent); 689 free(fcontent1); 690 return 0; 691 }else{ 692 free(fcontent); 693 free(fcontent1); 694 return -1; 695 } 696 }else{ 697 free(tmpPath); 698 free(fcontent); 699 return -1; 700 } 701 } 702 free(logPath); 703 free(tmpPath); 704 } 705 } 706 return -1; 707 } 708 651 709 bool runUpload(maps** conf){ 652 710 SSHCON *test=ssh_connect(*conf); … … 665 723 getMapArray(queueMaps->content,"targetPath",i) 666 724 }; 667 /**/zooLock* lck; 668 if((lck=lockFile(*conf,argv[1]->value,'w'))!=NULL){/**/ 669 if(ssh_copy(*conf,argv[1]->value,argv[2]->value,ssh_get_cnt(*conf))!=true){ 670 char* templateStr=_("Unable to copy over SSH the file requested for setting the value of %s."); 671 char *tmpMessage=(char*)malloc((strlen(templateStr)+strlen(argv[0]->value)+1)*sizeof(char)); 672 sprintf(tmpMessage,templateStr,argv[0]->value); 673 setMapInMaps(*conf,"lenv","message",tmpMessage); 674 free(tmpMessage); 675 unlockFile(*conf,lck); 725 if(fileMd5Check(conf,argv[1]->value,argv[2]->value)<0){ 726 /**/zooLock* lck; 727 if((lck=lockFile(*conf,argv[1]->value,'w'))!=NULL){/**/ 728 if(ssh_copy(*conf,argv[1]->value,argv[2]->value,ssh_get_cnt(*conf))!=true){ 729 char* templateStr=_("Unable to copy over SSH the file requested for setting the value of %s."); 730 char *tmpMessage=(char*)malloc((strlen(templateStr)+strlen(argv[0]->value)+1)*sizeof(char)); 731 sprintf(tmpMessage,templateStr,argv[0]->value); 732 setMapInMaps(*conf,"lenv","message",tmpMessage); 733 free(tmpMessage); 734 unlockFile(*conf,lck); 735 return false; 736 } 737 /**/unlockFile(*conf,lck); 738 }else{ 739 setMapInMaps(*conf,"lenv","message",_("Unable to lock the file for upload!")); 676 740 return false; 677 } 678 /**/unlockFile(*conf,lck); 679 }else{ 680 setMapInMaps(*conf,"lenv","message",_("Unable to lock the file for upload!")); 681 return false; 682 }/**/ 741 }/**/ 742 } 683 743 } 684 744 }
Note: See TracChangeset
for help on using the changeset viewer.