summaryrefslogtreecommitdiff
path: root/source4/ntvfs/posix/pvfs_streams.c
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2009-10-18 14:19:27 +1100
committerAndrew Tridgell <tridge@samba.org>2009-10-18 15:06:13 +1100
commit764c09e6bc92d8ccd33b44d6cc80e82a9b4d76f0 (patch)
treed591e33e4f3689552d0e5bf80f3742414971af4b /source4/ntvfs/posix/pvfs_streams.c
parent44612c74a6de8becd8f8dc51590616ba792ca13f (diff)
downloadsamba-764c09e6bc92d8ccd33b44d6cc80e82a9b4d76f0.tar.gz
samba-764c09e6bc92d8ccd33b44d6cc80e82a9b4d76f0.tar.bz2
samba-764c09e6bc92d8ccd33b44d6cc80e82a9b4d76f0.zip
s4-streams: fixed handling of stream rename and overwrite
Diffstat (limited to 'source4/ntvfs/posix/pvfs_streams.c')
-rw-r--r--source4/ntvfs/posix/pvfs_streams.c24
1 files changed, 17 insertions, 7 deletions
diff --git a/source4/ntvfs/posix/pvfs_streams.c b/source4/ntvfs/posix/pvfs_streams.c
index 6b39fb6066..4da95432c1 100644
--- a/source4/ntvfs/posix/pvfs_streams.c
+++ b/source4/ntvfs/posix/pvfs_streams.c
@@ -240,7 +240,7 @@ static NTSTATUS pvfs_stream_update_size(struct pvfs_state *pvfs, struct pvfs_fil
rename a stream
*/
NTSTATUS pvfs_stream_rename(struct pvfs_state *pvfs, struct pvfs_filename *name, int fd,
- const char *new_name)
+ const char *new_name, bool overwrite)
{
struct xattr_DosStreams *streams;
int i, found_old, found_new;
@@ -289,17 +289,27 @@ NTSTATUS pvfs_stream_rename(struct pvfs_state *pvfs, struct pvfs_filename *name,
struct xattr_DosStream *s = &streams->streams[found_old];
s->name = new_name;
} else {
- /* remove the old one and replace with the new one */
- streams->streams[found_old].name = new_name;
- memmove(&streams->streams[found_new],
- &streams->streams[found_new+1],
- sizeof(streams->streams[0]) *
- (streams->num_streams - (found_new+1)));
+ if (!overwrite) {
+ return NT_STATUS_OBJECT_NAME_COLLISION;
+ }
+ if (found_old != found_new) {
+ /* remove the old one and replace with the new one */
+ streams->streams[found_old].name = new_name;
+ memmove(&streams->streams[found_new],
+ &streams->streams[found_new+1],
+ sizeof(streams->streams[0]) *
+ (streams->num_streams - (found_new+1)));
+ streams->num_streams--;
+ }
}
status = pvfs_streams_save(pvfs, name, fd, streams);
talloc_free(streams);
+ /* update the in-memory copy of the name of the open file */
+ talloc_free(name->stream_name);
+ name->stream_name = talloc_strdup(name, new_name);
+
return status;
}