lavf/libsmbclient: implement move and delete callbacks

Reviewed-by: Lukasz Marek <lukasz.m.luki2@gmail.com>
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
Mariusz Szczepańczyk 2015-06-22 04:58:00 +02:00 committed by Michael Niedermayer
parent 94a43dcff1
commit 71034163ac

View File

@ -287,6 +287,67 @@ static int libsmbc_close_dir(URLContext *h)
return 0; return 0;
} }
static int libsmbc_delete(URLContext *h)
{
LIBSMBContext *libsmbc = h->priv_data;
int ret;
struct stat st;
if ((ret = libsmbc_connect(h)) < 0)
goto cleanup;
if ((libsmbc->fd = smbc_open(h->filename, O_WRONLY, 0666)) < 0) {
ret = AVERROR(errno);
goto cleanup;
}
if (smbc_fstat(libsmbc->fd, &st) < 0) {
ret = AVERROR(errno);
goto cleanup;
}
smbc_close(libsmbc->fd);
libsmbc->fd = -1;
if (S_ISDIR(st.st_mode)) {
if (smbc_rmdir(h->filename) < 0) {
ret = AVERROR(errno);
goto cleanup;
}
} else {
if (smbc_unlink(h->filename) < 0) {
ret = AVERROR(errno);
goto cleanup;
}
}
ret = 0;
cleanup:
libsmbc_close(h);
return ret;
}
static int libsmbc_move(URLContext *h_src, URLContext *h_dst)
{
LIBSMBContext *libsmbc = h_src->priv_data;
int ret;
if ((ret = libsmbc_connect(h_src)) < 0)
goto cleanup;
if ((libsmbc->dh = smbc_rename(h_src->filename, h_dst->filename)) < 0) {
ret = AVERROR(errno);
goto cleanup;
}
ret = 0;
cleanup:
libsmbc_close(h_src);
return ret;
}
#define OFFSET(x) offsetof(LIBSMBContext, x) #define OFFSET(x) offsetof(LIBSMBContext, x)
#define D AV_OPT_FLAG_DECODING_PARAM #define D AV_OPT_FLAG_DECODING_PARAM
#define E AV_OPT_FLAG_ENCODING_PARAM #define E AV_OPT_FLAG_ENCODING_PARAM
@ -311,6 +372,8 @@ URLProtocol ff_libsmbclient_protocol = {
.url_write = libsmbc_write, .url_write = libsmbc_write,
.url_seek = libsmbc_seek, .url_seek = libsmbc_seek,
.url_close = libsmbc_close, .url_close = libsmbc_close,
.url_delete = libsmbc_delete,
.url_move = libsmbc_move,
.url_open_dir = libsmbc_open_dir, .url_open_dir = libsmbc_open_dir,
.url_read_dir = libsmbc_read_dir, .url_read_dir = libsmbc_read_dir,
.url_close_dir = libsmbc_close_dir, .url_close_dir = libsmbc_close_dir,