public String getLuid(SyncItem item) { JSONFileObject json = ((JSONSyncItem) item).getJSONFileObject(); String fileName = json.getName(); String localFullName = getFileFullName(fileName); return localFullName; }
/** * Twin detection implementation * * @param item * @return the twin sync item, whose key is the LUID */ public SyncItem findTwin(SyncItem item) { if (item instanceof JSONSyncItem) { JSONFileObject json = ((JSONSyncItem) item).getJSONFileObject(); String fileName = json.getName(); String fullName = getFileFullName(fileName); // Does this existing in our directory? if (Log.isLoggable(Log.DEBUG)) { Log.debug(TAG_LOG, "Checking for twin for: " + fileName); } FileAdapter fa = null; try { fa = new FileAdapter(fullName); if (fa.exists() && fa.getSize() == json.getSize()) { if (Log.isLoggable(Log.DEBUG)) { Log.debug(TAG_LOG, "Twin found"); } item.setKey(fullName); return item; } } catch (Throwable t) { Log.error(TAG_LOG, "Cannot check for twins", t); } finally { if (fa != null) { try { fa.close(); } catch (IOException ioe) { } } } } // No twin found return null; }
protected SyncItem getItemContent(SyncItem item) throws SyncException { FileAdapter file = null; try { String fileFullName = item.getKey(); String fileName = getFileNameFromKey(fileFullName); file = new FileAdapter(fileFullName); long size = file.getSize(); long modified = file.lastModified(); JSONFileObject jsonFileObject = new JSONFileObject(); jsonFileObject.setName(fileName); jsonFileObject.setSize(size); jsonFileObject.setCreationdate(modified); jsonFileObject.setLastModifiedDate(modified); jsonFileObject.setMimetype(getContentTypeFromFileName(fileName)); FileSyncItem syncItem = new FileSyncItem( fileFullName, item.getKey(), getConfig().getType(), item.getState(), item.getParent(), jsonFileObject); // Set the item old key to handle renames if (getTracker() instanceof CacheTrackerWithRenames) { CacheTrackerWithRenames tracker = (CacheTrackerWithRenames) getTracker(); if (tracker.isRenamedItem(item.getKey())) { String oldKey = tracker.getRenamedFileName(item.getKey()); if (Log.isLoggable(Log.DEBUG)) { Log.debug(TAG_LOG, "Setting item old key: " + oldKey); } syncItem.setOldKey(oldKey); if (oldKey != null) { syncItem.setItemKeyUpdated(true); } } else { syncItem.setOldKey(null); syncItem.setItemKeyUpdated(false); } } // Check if the sync item content has been updated. if (getTracker() instanceof CacheTrackerWithRenames) { CacheTrackerWithRenames tracker = (CacheTrackerWithRenames) getTracker(); if (tracker.isRenamedItem(item.getKey())) { boolean itemUpdated = tracker.isRenamedItemUpdated(syncItem.getOldKey(), syncItem.getKey()); if (Log.isLoggable(Log.DEBUG)) { Log.debug(TAG_LOG, "Setting item content updated: " + itemUpdated); } syncItem.setItemContentUpdated(itemUpdated); } } return syncItem; } catch (Exception e) { throw new SyncException( SyncException.CLIENT_ERROR, "Cannot create SyncItem: " + e.toString()); } finally { try { if (file != null) { file.close(); } } catch (IOException ex) { } } }