Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dfs_rename should work when the new file exsits #92

Closed
grissiom opened this issue May 18, 2013 · 3 comments
Closed

dfs_rename should work when the new file exsits #92

grissiom opened this issue May 18, 2013 · 3 comments

Comments

@grissiom
Copy link
Member

http://linux.die.net/man/3/rename

If the link named by the new argument exists, it shall be removed and old renamed to new. In this case, a link named new shall remain visible to other processes throughout the renaming operation and refer either to the file referred to by new or old before the operation began.

But in current dfs_rename, it will return -17, i.e., EEXIST. The link above said rename could return EEXIST, but in a different situation:

EEXIST or ENOTEMPTY
The link named by new is a directory that is not an empty directory.

This bug makes rename unusable in most of the scenarios.

@grissiom
Copy link
Member Author

ping

@BernardXiong
Copy link
Member

@prife please provide your comments.

@prife
Copy link
Contributor

prife commented Mar 9, 2014

sorry for responding so late.

int dfs_file_rename(const char *oldpath, const char *newpath)
{
    int result;
    struct dfs_filesystem *oldfs, *newfs;
    char *oldfullpath, *newfullpath;

    result = DFS_STATUS_OK;
    newfullpath = RT_NULL;
    oldfullpath = RT_NULL;

    oldfullpath = dfs_normalize_path(RT_NULL, oldpath);
    if (oldfullpath == RT_NULL)
    {
        result = -DFS_STATUS_ENOENT;
        goto __exit;
    }

    newfullpath = dfs_normalize_path(RT_NULL, newpath);
    if (newfullpath == RT_NULL)
    {
        result = -DFS_STATUS_ENOENT;
        goto __exit;
    }

    oldfs = dfs_filesystem_lookup(oldfullpath);
    newfs = dfs_filesystem_lookup(newfullpath);

    if (oldfs == newfs)
    {
        if (oldfs->ops->rename == RT_NULL)
        {
            result = -DFS_STATUS_ENOSYS;
        }
        else
        {
            if (oldfs->ops->flags & DFS_FS_FLAG_FULLPATH)
                result = oldfs->ops->rename(oldfs, oldfullpath, newfullpath);
            else
                /* use sub directory to rename in file system */
                result = oldfs->ops->rename(oldfs,
                                            dfs_subdir(oldfs->path, oldfullpath),
                                            dfs_subdir(newfs->path, newfullpath));
        }
    }
    else
    {
        result = -DFS_STATUS_EXDEV;
    }

__exit:
    rt_free(oldfullpath);
    rt_free(newfullpath);

    /* not at same file system, return EXDEV */
    return result;
}

what rename in RTT return seems depends the rename implemented on the specific fs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants