Search in sources :

Example 1 with FMFileOwner

use of com.biglybt.core.diskmanager.file.FMFileOwner in project BiglyBT by BiglySoftware.

the class FMFileImpl method generateEvidence.

protected static void generateEvidence(IndentWriter writer) {
    writer.println(file_map.size() + " FMFile Reservations");
    try {
        writer.indent();
        try {
            file_map_mon.enter();
            Iterator it = file_map.keySet().iterator();
            while (it.hasNext()) {
                String key = (String) it.next();
                List owners = (List) file_map.get(key);
                Iterator it2 = owners.iterator();
                String str = "";
                while (it2.hasNext()) {
                    Object[] entry = (Object[]) it2.next();
                    FMFileOwner owner = (FMFileOwner) entry[0];
                    Boolean write = (Boolean) entry[1];
                    String reason = (String) entry[2];
                    str += (str.length() == 0 ? "" : ", ") + owner.getName() + "[" + (write.booleanValue() ? "write" : "read") + "/" + reason + "]";
                }
                writer.println(Debug.secretFileName(key) + " -> " + str);
            }
        } finally {
            file_map_mon.exit();
        }
        FMFileManagerImpl.generateEvidence(writer);
    } finally {
        writer.exdent();
    }
}
Also used : FMFileOwner(com.biglybt.core.diskmanager.file.FMFileOwner)

Example 2 with FMFileOwner

use of com.biglybt.core.diskmanager.file.FMFileOwner in project BiglyBT by BiglySoftware.

the class FMFileImpl method reserveAccess.

private void reserveAccess(String reason) throws FMFileManagerException {
    if (clone) {
        return;
    }
    try {
        file_map_mon.enter();
        // System.out.println( "FMFile::reserveAccess:" + canonical_path + "("+ owner.getName() + ")" + " [" + (access_mode==FM_WRITE?"write":"read") + "]" + " - " + Debug.getCompressedStackTrace());
        List owners = (List) file_map.get(canonical_path);
        Object[] my_entry = null;
        if (owners == null) {
            Debug.out("reserveAccess fail");
            throw (new FMFileManagerException("File '" + canonical_path + "' has not been reserved (no entries), '" + owner.getName() + "'"));
        }
        for (Iterator it = owners.iterator(); it.hasNext(); ) {
            Object[] entry = (Object[]) it.next();
            String entry_name = ((FMFileOwner) entry[0]).getName();
            if (owner.getName().equals(entry_name)) {
                my_entry = entry;
            }
        }
        if (my_entry == null) {
            Debug.out("reserveAccess fail");
            throw (new FMFileManagerException("File '" + canonical_path + "' has not been reserved (not found), '" + owner.getName() + "'"));
        }
        my_entry[1] = Boolean.valueOf(access_mode == FM_WRITE);
        my_entry[2] = reason;
        int read_access = 0;
        int write_access = 0;
        int write_access_lax = 0;
        TOTorrentFile my_torrent_file = owner.getTorrentFile();
        StringBuilder users_sb = owners.size() == 1 ? null : new StringBuilder(128);
        for (Iterator it = owners.iterator(); it.hasNext(); ) {
            Object[] entry = (Object[]) it.next();
            FMFileOwner this_owner = (FMFileOwner) entry[0];
            if (((Boolean) entry[1]).booleanValue()) {
                write_access++;
                TOTorrentFile this_tf = this_owner.getTorrentFile();
                if (my_torrent_file != null && this_tf != null && my_torrent_file.getLength() == this_tf.getLength()) {
                    write_access_lax++;
                }
                if (users_sb != null) {
                    if (users_sb.length() > 0) {
                        users_sb.append(",");
                    }
                    users_sb.append(this_owner.getName());
                    users_sb.append(" [write]");
                }
            } else {
                read_access++;
                if (users_sb != null) {
                    if (users_sb.length() > 0) {
                        users_sb.append(",");
                    }
                    users_sb.append(this_owner.getName());
                    users_sb.append(" [read]");
                }
            }
        }
        if (write_access > 1 || (write_access == 1 && read_access > 0)) {
            if (!COConfigurationManager.getBooleanParameter("File.strict.locking")) {
                if (write_access_lax == write_access) {
                    return;
                }
            }
            Debug.out("reserveAccess fail");
            throw (new FMFileManagerException("File '" + canonical_path + "' is in use by '" + (users_sb == null ? "eh?" : users_sb.toString()) + "'"));
        }
    } finally {
        file_map_mon.exit();
    }
}
Also used : FMFileManagerException(com.biglybt.core.diskmanager.file.FMFileManagerException) TOTorrentFile(com.biglybt.core.torrent.TOTorrentFile) FMFileOwner(com.biglybt.core.diskmanager.file.FMFileOwner)

Aggregations

FMFileOwner (com.biglybt.core.diskmanager.file.FMFileOwner)2 FMFileManagerException (com.biglybt.core.diskmanager.file.FMFileManagerException)1 TOTorrentFile (com.biglybt.core.torrent.TOTorrentFile)1