-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathremove_file.c
50 lines (43 loc) · 1.16 KB
/
remove_file.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/* Copyright (C) 2000 [email protected]
This is free software distributed under the terms of the
GNU Public License. See the file COPYING for details.
$Id$ */
#include <string.h>
#include "opennap.h"
#include "debug.h"
/* 102 <filename> */
HANDLER (remove_file)
{
USER *user;
DATUM *info;
unsigned int fsize;
(void) tag;
(void) len;
ASSERT (validate_connection (con));
CHECK_USER_CLASS ("remove_file");
user = con->user;
if (!user->shared)
{
send_cmd (con, MSG_SERVER_NOSUCH, "Not sharing any files");
return;
}
/* find the file in the user's list */
info = hash_lookup (con->uopt->files, pkt);
if (!info)
{
send_cmd (con, MSG_SERVER_NOSUCH, "Not sharing that file");
return;
}
/* adjust the global state information */
fsize = info->size / 1024; /* kB */
user->libsize -= fsize;
Num_Gigs -= fsize;
ASSERT (Num_Files > 0);
Num_Files--;
ASSERT (Local_Files > 0);
Local_Files--;
user->shared--;
user->unsharing = 1; /* note that we are unsharing */
/* this invokes free_datum() indirectly */
hash_remove (con->uopt->files, info->filename);
}