// File: /workspace/github_c_makefile_star2_O3/evanwire[P]GitClone/server.c
// Function: update
void update(char* command, int connfd){
  //Parse project name from the message received from the client
  char project_name[strlen(command) - 1];
  memset(project_name, 0, sizeof(project_name));
  int i;
  for(i = 2; i < strlen(command); i++){
      if(command[i]){
        project_name[i - 2] = command[i];
      }
      
  }

  //Set up buffer for responding to client
  char sendBuff[1024];
  memset(sendBuff, '\0', sizeof(sendBuff));

  //Attempt to open directory with the name specified by the client
  DIR* dir = opendir(project_name);

  //Report an error assuming the project does not exist
  if(ENOENT == errno){
    closedir(dir);
    strcpy(sendBuff, "x");
    printf("Message: -%s- size: %d\n", sendBuff, strlen(sendBuff));
    write(connfd, sendBuff, strlen(sendBuff));
    return;

  //project does exist, so continue
  }else if (dir){
    //do nothing and continue

  //opendir() failed
  }else{
    printf("\nERROR: opendir() failed.\n");
    strcpy(sendBuff, "e");
    printf("Message: -%s- size: %d\n", sendBuff, strlen(sendBuff));
    write(connfd, sendBuff, strlen(sendBuff));
    return;
  }

  //Open the needed Manifest file
  char* manifestPath = (char*)malloc(sizeof(project_name)+11);
  strcpy(manifestPath,project_name);
  strcat(manifestPath,"/.Manifest");

  int manifest_fd = open(manifestPath, O_RDONLY);

    /*
    TODO: Communicate errors like these to clients in an efficient way
        -Make a method for only communicating errors
    */
  if(manifest_fd < 0){
    printf("\nError: Was unable to open/create the .Manifest file. Please try again.\n");
    exit(1);
  }
  char* fileContents=readFile(manifestPath);
  printf("Message: -%s- size: %d\n", fileContents, strlen(fileContents));
  write(connfd, fileContents, strlen(fileContents));
  return;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x400, %rsp            # imm = 0x400
movl %esi, %ebx
movq %rdi, %r12
callq 0x10b0
movq %rax, %r14
leaq -0x1(%rax), %rdx
movq %rsp, %r15
addq $0xe, %rax
andq $-0x10, %rax
subq %rax, %r15
movq %r15, %rsp
movq %r15, %rdi
xorl %esi, %esi
callq 0x10d0
cmpq $0x3, %r14
jb 0x296e
leaq -0x2(%r14), %rax
xorl %ecx, %ecx
movb 0x2(%r12,%rcx), %dl
testb %dl, %dl
je 0x2966
movb %dl, (%r15,%rcx)
incq %rcx
cmpq %rcx, %rax
jne 0x2959
leaq -0x420(%rbp), %rdi
movl $0x400, %edx            # imm = 0x400
xorl %esi, %esi
callq 0x10d0
movq %r15, %rdi
callq 0x1220
movq %rax, %r12
callq 0x1030
cmpl $0x2, (%rax)
jne 0x29b0
movq %r12, %rdi
callq 0x1270
leaq -0x420(%rbp), %r14
movw $0x78, (%r14)
jmp 0x2a67
testq %r12, %r12
je 0x2a4e
addq $0xa, %r14
movq %r14, %rdi
callq 0x11e0
movq %rax, %r14
movq %rax, %rdi
movq %r15, %rsi
callq 0x1160
movq %r14, %rdi
callq 0x10b0
movabsq $0x6566696e614d2e2f, %rcx # imm = 0x6566696E614D2E2F
movq %rcx, (%r14,%rax)
movl $0x747365, 0x7(%r14,%rax) # imm = 0x747365
movq %r14, %rdi
xorl %esi, %esi
xorl %eax, %eax
callq 0x1100
testl %eax, %eax
js 0x2aa5
movq %r14, %rdi
callq 0x3333
movq %rax, %r14
movq %rax, %rdi
callq 0x10b0
leaq 0x18b9(%rip), %rdi      # 0x42d9
movq %r14, %rsi
movq %rax, %rdx
xorl %eax, %eax
callq 0x1040
movq %r14, %rdi
callq 0x10b0
movl %ebx, %edi
movq %r14, %rsi
movq %rax, %rdx
leaq -0x20(%rbp), %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x10a0
leaq 0x1c44(%rip), %rdi      # 0x4699
callq 0x1240
leaq -0x420(%rbp), %r14
movw $0x65, (%r14)
movq %r14, %rdi
callq 0x10b0
leaq 0x1863(%rip), %rdi      # 0x42d9
movq %r14, %rsi
movq %rax, %rdx
xorl %eax, %eax
callq 0x1040
movq %r14, %rdi
callq 0x10b0
movl %ebx, %edi
movq %r14, %rsi
movq %rax, %rdx
callq 0x10a0
leaq -0x20(%rbp), %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1c07(%rip), %rdi      # 0x46b3
callq 0x1240
movl $0x1, %edi
callq 0x11b0