Public feed #726973

Anonymous

public text v1 · immutable
Raw Edit
·published 2007-10-05 17:23 UTC
rendered paste body
int n_mirror(string *args, struct shell_state *sh) {
	struct afc_directory *dir;
	char *dirent;
	
	if (args[1] == "" ) {
  		ifNotQuiet cout << "mirror: please specify local dir." << endl;
	    return SHELL_CONTINUE;
  }
  
  ifNotQuiet cout << " mirror to " << args[1] << endl;
	
  string base = string(sh->remote_path);
  mkdir((args[1] + sh->remote_path).c_str());
  if (AFCDirectoryOpen(sh->conn, (char*)base.c_str(), &dir)) {
      ifNotQuiet cout << "oops getdir " << base << endl;
      return SHELL_CONTINUE;
   }
   while (1) {
      AFCDirectoryRead(0, dir, &dirent);
      if (!dirent) {
         break;
      }
      if( strcmp(dirent,".") == 0 || strcmp(dirent,"..") == 0 ) {
         continue;
      }
      string currentPhone = base + "/" + dirent;
      string currentLocal = args[1] + "/" + currentPhone;
      if (dirExists(sh->conn, (char*)currentPhone.c_str())) {
         mkdir(currentLocal.c_str());
         sh->remote_path = currentPhone;
         n_mirror(args, sh);
      }
      else {
         string copyArgs[3];
         copyArgs[0] = args[0];
         copyArgs[1] = currentPhone;
         copyArgs[2] = currentLocal;
         n_getfile(copyArgs, sh);
      }
   }
   return SHELL_CONTINUE;
}