Пример #1
0
bool OsFile_rename(const JvmPathChar *from, const JvmPathChar *to) {
  const int from_name_len = fn_strlen(from);
  const int to_name_len = fn_strlen(to);
  pcsl_string pcsl_filename_from = PCSL_STRING_NULL;
  pcsl_string pcsl_filename_to = PCSL_STRING_NULL;

  GUARANTEE(sizeof(jchar) == sizeof(JvmPathChar), "Types must match");

  if (pcsl_string_convert_from_utf16(from, 
                                     from_name_len, 
                                     &pcsl_filename_from) != PCSL_STRING_OK) {
    return -1;
  }

  if (pcsl_string_convert_from_utf16(to, 
                                     to_name_len, 
                                     &pcsl_filename_to) != PCSL_STRING_OK) {
    return -1;
  }

  int result = pcsl_file_rename(&pcsl_filename_from, &pcsl_filename_to);

  pcsl_string_free(&pcsl_filename_from);
  pcsl_string_free(&pcsl_filename_to);

  return (result == 0) ? true : false;
}
Пример #2
0
/*
 * Rename a file in storage.
 *
 * If not successful *ppszError will set to point to an error string,
 * on success it will be set to NULL.
 */
void
storage_rename_file(char** ppszError, const pcsl_string* oldFilename_str,
                    const pcsl_string* newFilename_str) {
    int status;
    *ppszError = NULL;

    DEBUGP2F("renaming %s", oldFilename_str);
    DEBUGP2F(" to %s\n", newFilename_str);

    if (!storage_file_exists(oldFilename_str)) {
        *ppszError = (char *)NOT_EXIST_RENAME_ERROR;
    }

    if (storage_file_exists(newFilename_str)) {
        storage_delete_file(ppszError, newFilename_str);
        if (*ppszError != NULL) {
            return;
        }
    }

    status = pcsl_file_rename(oldFilename_str, newFilename_str);

    if (status < 0) {
        *ppszError = storage_get_last_file_error("storageRename", newFilename_str);
        return;
    }

    *ppszError = NULL;
}