Example #1
0
/**
 * hdfsRename - Rename file.
 *
 * @param fs The configured filesystem handle.
 * @param oldPath The path of the source file.
 * @param newPath The path of the destination file.
 * @return Returns 0 on success, -1 on error.
 */
int
hdfsRename(hdfsFS fs, const char* oldPath, const char* newPath)
{
	struct hdfs_object *ex = NULL;
	bool b;
	struct hdfsFS_internal *client = fs;
	char *oldPath_abs, *newPath_abs;
	int res = 0;

	oldPath_abs = _makeabs(fs, oldPath);
	newPath_abs = _makeabs(fs, newPath);

	b = hdfs_rename(client->fs_namenode, oldPath_abs, newPath_abs, &ex);
	if (ex) {
		ERR(EIO, "rename(): %s", hdfs_exception_get_message(ex));
		hdfs_object_free(ex);
		res = -1;
		goto out;
	}
	
	if (!b) {
		ERR(EINVAL, "rename() failed (on '%s' -> '%s')", oldPath_abs, newPath_abs);
		res = -1;
		goto out;
	}

out:
	if (oldPath_abs != oldPath)
		free(oldPath_abs);
	if (newPath_abs != newPath)
		free(newPath_abs);
	return res;
}
Example #2
0
END_TEST

START_TEST(test_rename)
{
	bool s;
	struct hdfs_object *e = NULL;
	const char *tf = "/HADOOFUS_TEST_RENAME",
	      *tf2 = "/HADOOFUS_TEST_RENAMED",
	      *client = "HADOOFUS_CLIENT";

	// Create the file first
	hdfs_create(h, tf, 0644, client, true/*overwrite*/,
	    false/*createparent*/, 1/*replication*/, 64*1024*1024, &e);
	if (e)
		ck_abort_msg("exception: %s", hdfs_exception_get_message(e));

	s = hdfs_rename(h, tf, tf2, &e);
	if (e)
		ck_abort_msg("exception: %s", hdfs_exception_get_message(e));
	ck_assert_msg(s, "rename returned false");

	// Cleanup
	s = hdfs_delete(h, tf2, false/*recurse*/, &e);
	if (e)
		ck_abort_msg("exception: %s", hdfs_exception_get_message(e));
	ck_assert_msg(s, "delete returned false");
}
Example #3
0
/**
 * hdfsMove - Move file from one filesystem to another.
 *
 * @param srcFS The handle to source filesystem.
 * @param src The path of source file.
 * @param dstFS The handle to destination filesystem.
 * @param dst The path of destination file.
 * @return Returns 0 on success, -1 on error.
 */
int
hdfsMove(hdfsFS srcFS_, const char* src, hdfsFS dstFS, const char* dst)
{
	int res = -1;
	bool b;
	struct hdfs_object *ex = NULL;
	struct hdfsFS_internal *srcFS = srcFS_;
	char *src_abs, *dst_abs;

	src_abs = _makeabs(srcFS, src);
	dst_abs = _makeabs(dstFS, dst);

	// Yeah this comparison isn't perfect. We don't have anything better.
	if (srcFS_ == dstFS) {
		b = hdfs_rename(srcFS->fs_namenode, src_abs, dst_abs, &ex);
		if (ex) {
			ERR(EIO, "rename failed: %s", hdfs_exception_get_message(ex));
			goto out;
		}
		if (!b)
			WARN("rename of '%s' returned false", src_abs);
	} else {

		res = hdfsCopy(srcFS_, src_abs, dstFS, dst_abs);
		if (res == -1) {
			ERR(errno, "hdfsCopy failed");
			goto out;
		}

		b = hdfs_delete(srcFS->fs_namenode, src_abs, false/*recurse*/, &ex);
		if (ex) {
			ERR(EIO, "delete failed: %s", hdfs_exception_get_message(ex));
			goto out;
		}
		if (!b)
			WARN("delete of '%s' returned false", src_abs);
	}

	res = 0;
out:
	if (src_abs != src)
		free(src_abs);
	if (dst_abs != dst)
		free(dst_abs);
	if (ex)
		hdfs_object_free(ex);
	return res;
}