コード例 #1
0
  @Override
  public byte[] getXAttr(long fileId, String uid, String key) throws DatabaseException {

    ResultSet<byte[], byte[]> it = null;
    try {

      // peform a prefix lookup
      byte[] prefix = BabuDBStorageHelper.createXAttrPrefixKey(fileId, uid, key);
      it = database.prefixLookup(XATTRS_INDEX, prefix, null).get();

      // check whether the entry is the correct one
      while (it.hasNext()) {

        Entry<byte[], byte[]> curr = it.next();
        BufferBackedXAttr xattr = new BufferBackedXAttr(curr.getKey(), curr.getValue());
        if (uid.equals(xattr.getOwner()) && key.equals(xattr.getKey())) return xattr.getValue();
      }

      return null;

    } catch (BabuDBException exc) {
      throw new DatabaseException(exc);
    } finally {
      if (it != null) it.free();
    }
  }
コード例 #2
0
  @Override
  public FileMetadata createSymLink(
      long fileId,
      long parentId,
      String fileName,
      int atime,
      int ctime,
      int mtime,
      String userId,
      String groupId,
      String ref,
      AtomicDBUpdate update) {

    // create metadata
    BufferBackedFileMetadata fileMetadata =
        new BufferBackedFileMetadata(
            parentId,
            fileName,
            userId,
            groupId,
            fileId,
            atime,
            ctime,
            mtime,
            ref.length(),
            0777,
            0,
            (short) 1,
            0,
            0,
            false);

    // create link target (XAttr)
    BufferBackedXAttr lt =
        new BufferBackedXAttr(fileId, SYSTEM_UID, LINK_TARGET_ATTR_NAME, ref.getBytes(), (short) 0);
    update.addUpdate(XATTRS_INDEX, lt.getKeyBuf(), lt.getValBuf());

    // update main metadata in the file index
    update.addUpdate(
        FILE_INDEX, fileMetadata.getFCMetadataKey(), fileMetadata.getFCMetadataValue());
    update.addUpdate(
        FILE_INDEX, fileMetadata.getRCMetadata().getKey(), fileMetadata.getRCMetadata().getValue());

    // add an entry to the file ID index
    update.addUpdate(
        FILE_ID_INDEX,
        BabuDBStorageHelper.createFileIdIndexKey(fileId, (byte) 3),
        BabuDBStorageHelper.createFileIdIndexValue(parentId, fileName));

    return fileMetadata;
  }
コード例 #3
0
  public void setXAttr(
      long fileId, String uid, String key, byte[] value, boolean init, AtomicDBUpdate update)
      throws DatabaseException {

    try {
      short collNumber =
          init ? -1 : BabuDBStorageHelper.findXAttrCollisionNumber(database, fileId, uid, key);

      BufferBackedXAttr xattr = new BufferBackedXAttr(fileId, uid, key, value, collNumber);
      update.addUpdate(XATTRS_INDEX, xattr.getKeyBuf(), value == null ? null : xattr.getValBuf());

      if (key.startsWith(SYS_ATTR_KEY_PREFIX + MRCHelper.POLICY_ATTR_PREFIX))
        notifyAttributeSet(volume.getId(), key, value == null ? null : new String(value));

    } catch (BabuDBException exc) {
      throw new DatabaseException(exc);
    }
  }