1 /*
2 * h_rnto.c
3 *
4 * (C)1998-2011 by Marc Huber <Marc.Huber@web.de>
5 * All rights reserved.
6 *
7 * $Id: h_rnto.c,v 1.10 2015/03/14 06:11:26 marc Exp marc $
8 *
9 */
10
11 #include "headers.h"
12
13 static const char rcsid[] __attribute__ ((used)) = "$Id: h_rnto.c,v 1.10 2015/03/14 06:11:26 marc Exp marc $";
14
h_rnto(struct context * ctx,char * arg)15 void h_rnto(struct context *ctx, char *arg)
16 {
17 char *t;
18 struct stat st;
19
20 DebugIn(DEBUG_COMMAND);
21
22 if (!ctx->last_command_was_rnfr)
23 reply(ctx, MSG_503_Use_RNFR_first);
24 else if ((t = buildpath(ctx, arg)) && !pickystat_path(ctx, &st, t) && (stat(t, &st), !rename(ctx->filename, t))) {
25 if (S_ISREG(st.st_mode))
26 quota_add(ctx, -st.st_size);
27
28 reply(ctx, MSG_250_File_renamed);
29 ctx->filename[0] = 0;
30 } else
31 reply(ctx, MSG_550_Permission_denied);
32
33 ctx->last_command_was_rnfr = 0;
34
35 DebugOut(DEBUG_COMMAND);
36 }
37