@Override
    public void deleteFile(String username, String filename) throws RemoteException {
        DbWrapper db = DbWrapper.getInstance();
        FileEntityDescription fd;
        try {
            fd = db.loadFileEntity(filename);
        } catch (SQLException ex) {
            throw new RemoteException(ex.getMessage());
        }
        System.out.println(username + " trying to delete " + fd.name + " of " + fd.ownerName + "which is private=" + fd.privateFile + " and writepermission " + fd.writepermission);



        if (fd.privateFile) {
            //private file
            if (username.compareTo(fd.ownerName) != 0) {
                //user different from owner
                throw new RemoteException("You are not allowed to delete this file, since it is private and you are not the owner");
            }
        } else {


            if ((!fd.writepermission) && username.compareTo(fd.ownerName) != 0) {

                throw new RemoteException("You are not allowed to delete this file, since it is public but you don't have write permission on it");
            }
        }
        try {
            String abspath=getPathOfFileGivenName(filename);
            
            System.out.println("Abs path: "  + abspath);
            DbWrapper.getInstance().deleteFile(filename);
            
            File f = new File(abspath);
            if (!f.exists()) {
                throw new IllegalArgumentException(
                        "Delete: no such file or directory: " + abspath);
            }

            if (!f.canWrite()) {
                throw new IllegalArgumentException("Delete: write protected: "
                        + abspath);
            }
            f.delete();

        } catch (IOException | SQLException ex) {
            throw new RemoteException(ex.getMessage());
        }
    }