--- samba-2.2.5/source/smbd/reply.c Tue Jun 18 21:13:48 2002 +++ reply.c.patch Wed Aug 14 16:50:02 2002 @@ -2021,6 +2021,66 @@ return NT_STATUS_OK; } +/******************************************************************** +check if file should be recycled +*********************************************************************/ +static int recycle(connection_struct *conn, char *fname, char *recycle_bin) +{ + char *base, *ext; + pstring bin, zfname, zbin; + int i=1, len, addlen; + int dir_mask=0700; + + SMB_BIG_UINT dfree,dsize,bsize; + + if(!recycle_bin || !*recycle_bin) { + DEBUG(3, ("recycle bin: share parameter not set, purging %s...\n", fname)); + return vfs_unlink(conn,fname); + } + + if(get_file_size(fname) == 0) { + DEBUG(3, ("recycle bin: file %s is empty, purging...\n", fname)); + return vfs_unlink(conn,fname); + } + + base = strrchr(fname, '/') + 1; + if(base == (char*)1) base = fname; + + ext = strrchr(base, '.'); + + pstrcpy(bin, recycle_bin); + pstrcat(bin, "/"); + pstrcat(bin, base); + + if(strcmp(fname,bin) == 0) { + DEBUG(3, ("recycle bin: file %s exists, purging...\n", fname)); + return vfs_unlink(conn,fname); + } + + len = strlen(bin); + addlen = sizeof(pstring)-len-1; + while(vfs_file_exist(conn,bin, NULL)) { + slprintf(bin+len, addlen, " (Copy #%d)", i++); + pstrcat(bin, ext); + } + + DEBUG(3, ("recycle bin: moving source=%s to dest=%s\n", fname, bin)); + sys_disk_free(".",True,&bsize,&dfree,&dsize); + if((unsigned int)dfree > 0) { + if(!directory_exist(recycle_bin,NULL)) { + DEBUG(3, ("recycle bin: directory %s nonexistant, creating...\n", recycle_bin)); + vfs_mkdir(conn,recycle_bin,dir_mask); + } + DEBUG(3, ("recycle bin: move successful\n")); + pstrcpy(zfname,dos_to_unix_static(fname)); + pstrcpy(zbin,dos_to_unix_static(bin)); + return vfswrap_rename(conn, zfname, zbin); + } else { + DEBUG(3, ("recycle bin: move failed, purging...\n")); + return vfs_unlink(conn,fname); + } +} + /**************************************************************************** The guts of the unlink command, split out so it may be called by the NT SMB code. @@ -2031,6 +2091,7 @@ pstring directory; pstring mask; char *p; + char *recycle_bin = lp_recyclebin(SNUM(conn)); int count=0; NTSTATUS error = NT_STATUS_OK; BOOL has_wild; @@ -2042,6 +2103,8 @@ rc = unix_convert(name,conn,0,&bad_path,&sbuf); + standard_sub_conn(conn,recycle_bin); + p = strrchr(name,'/'); if (!p) { pstrcpy(directory,"."); @@ -2073,7 +2136,7 @@ if (!NT_STATUS_IS_OK(error)) return error; - if (vfs_unlink(conn,directory) == 0) + if (recycle(conn,directory,recycle_bin) == 0) count++; } else { void *dirptr = NULL; @@ -2103,7 +2166,7 @@ error = can_delete(fname,conn,dirtype); if (!NT_STATUS_IS_OK(error)) continue; - if (vfs_unlink(conn,fname) == 0) + if (recycle(conn,fname,recycle_bin) == 0) count++; DEBUG(3,("unlink_internals: succesful unlink [%s]\n",fname)); } @@ -4109,6 +4172,7 @@ pstring directory; pstring mask,newname; char *p; + char *recycle_bin = lp_recyclebin(SNUM(conn)); int count=0; int error = ERRnoaccess; int err = 0; @@ -4163,6 +4227,8 @@ return ERROR_DOS(ERRSRV,ERRerror); } + standard_sub_conn(conn,recycle_bin); + p = strrchr(name,'/'); if (!p) { pstrcpy(directory,"./");