From: Vinicius Costa Gomes <vinicius.gomes@openbossa.org>
To: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
Cc: linux-bluetooth@vger.kernel.org
Subject: Re: [PATCH obexd] client: Fix not checking if destination exist while renaming file
Date: Tue, 29 May 2012 11:25:37 -0300 [thread overview]
Message-ID: <20120529142537.GB13737@samus> (raw)
In-Reply-To: <1338293498-2356-1-git-send-email-luiz.dentz@gmail.com>
Hi Luiz,
On 15:11 Tue 29 May, Luiz Augusto von Dentz wrote:
> From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
>
> rename return an error if the destination directory doesn't exist, so
> in case it doesn't exist it should be created before calling rename.
> ---
> client/transfer.c | 27 +++++++++++++++++++++++++--
> 1 files changed, 25 insertions(+), 2 deletions(-)
>
> diff --git a/client/transfer.c b/client/transfer.c
> index 3065c9c..772834f 100644
> --- a/client/transfer.c
> +++ b/client/transfer.c
> @@ -715,11 +715,34 @@ int obc_transfer_set_filename(struct obc_transfer *transfer,
> const char *filename)
> {
> int err;
> + struct stat st;
> + char *dirname;
> + gboolean dir = FALSE;
> +
> + dirname = g_path_get_dirname(filename);
> + if (stat(dirname, &st) < 0) {
> + if (errno != ENOENT) {
> + error("stat(): %s (%d)", strerror(errno), errno);
> + return -errno;
> + }
> +
> + if (mkdir(dirname, 0755) < 0) {
For example, if my /tmp is empty, and "dirname" is "/tmp/foo/bar", this
would fail, right? i.e. mkdir() isn't able to create two (or more) levels
at a time.
So for consistency, I would prefer if the error that the directory
doesn't exist is returned, and the user creates the directory himself.
This is mostly for FTP, right?
> + error("mkdir(): %s (%d)", strerror(errno), errno);
> + return -errno;
> + }
> +
> + dir = TRUE;
> + }
>
> err = rename(transfer->filename, filename);
> if (err < 0) {
> - error("rename(): %s (%d)", strerror(errno), errno);
> - return -errno;
> + err = -errno;
> +
> + if (dir)
> + rmdir(dirname);
> +
> + error("rename(): %s (%d)", strerror(-err), -err);
> + return -err;
> }
>
> g_free(transfer->filename);
> --
> 1.7.7.6
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
Cheers,
--
Vinicius
next prev parent reply other threads:[~2012-05-29 14:25 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-29 12:11 [PATCH obexd] client: Fix not checking if destination exist while renaming file Luiz Augusto von Dentz
2012-05-29 14:25 ` Vinicius Costa Gomes [this message]
2012-05-29 18:08 ` Luiz Augusto von Dentz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20120529142537.GB13737@samus \
--to=vinicius.gomes@openbossa.org \
--cc=linux-bluetooth@vger.kernel.org \
--cc=luiz.dentz@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox