public void clearCryptoRepoFileDeleted(String path) { path = prefixPath(path); try (final LocalRepoTransaction transaction = getLocalRepoManager().beginWriteTransaction(); ) { getCryptree(transaction).clearCryptoRepoFileDeleted(path); transaction.commit(); } }
private void putPaddingMetaData(String path, SsNormalFileDto fromNormalFileDto) { path = prefixPath(path); // does a null-check assertNotNull("fromNormalFileDto", fromNormalFileDto); final File file = getFile(path); try (final LocalRepoTransaction transaction = getLocalRepoManager().beginWriteTransaction(); ) { final RepoFile repoFile = transaction .getDao(RepoFileDao.class) .getRepoFile(getLocalRepoManager().getLocalRoot(), file); if (!(repoFile instanceof NormalFile)) { throw new IllegalStateException( String.format( "RepoFile is not an instance of NormalFile! repoFile=%s file=%s", repoFile, file)); } final SsNormalFile normalFile = (SsNormalFile) repoFile; normalFile.setLengthWithPadding(fromNormalFileDto.getLengthWithPadding()); final Map<Long, SsFileChunk> offset2FileChunk = new HashMap<>(normalFile.getFileChunks().size()); for (FileChunk fc : normalFile.getFileChunks()) offset2FileChunk.put(fc.getOffset(), (SsFileChunk) fc); for (final FileChunkDto fcDto : fromNormalFileDto.getFileChunkDtos()) { SsFileChunkDto fileChunkDto = (SsFileChunkDto) fcDto; // If there is at least 1 byte of real data, the SHA1 (as well as the entire FileChunk // object) // is created from it and we don't need to store the FileChunk we received from the other // side. if (fileChunkDto.getLength() > 0) continue; boolean isNew = false; SsFileChunk fileChunk = offset2FileChunk.get(fileChunkDto.getOffset()); if (fileChunk == null) { isNew = true; fileChunk = (SsFileChunk) createObject(FileChunk.class); fileChunk.setNormalFile(normalFile); fileChunk.setOffset(fileChunkDto.getOffset()); } fileChunk.makeWritable(); fileChunk.setLength(fileChunkDto.getLength()); fileChunk.setLengthWithPadding(fileChunkDto.getLengthWithPadding()); fileChunk.setSha1(fileChunkDto.getSha1()); fileChunk.makeReadOnly(); if (isNew) normalFile.getFileChunks().add(fileChunk); } transaction.commit(); } }
protected void createAndPersistPreliminaryCollision( final LocalRepoManager localRepoManager, final File file, String localPath, Uid cryptoRepoFileId) { assertNotNull("localRepoManager", localRepoManager); if (localPath == null) assertNotNull("localPath/file", file); logger.debug( "createAndPersistPreliminaryCollision: localRoot='{}' localRepositoryId={} file='{}' localPath='{}' cryptoRepoFileId={}", localRepoManager.getLocalRoot(), getRepositoryId(), (file == null ? "" : file.getAbsolutePath()), (localPath == null ? "" : localPath), cryptoRepoFileId); try (final LocalRepoTransaction tx = localRepoManager.beginWriteTransaction(); ) { if (localPath == null) localPath = '/' + localRepoManager .getLocalRoot() .relativize(file) .replace(FILE_SEPARATOR_CHAR, '/'); final PreliminaryCollisionDao pcDao = tx.getDao(PreliminaryCollisionDao.class); PreliminaryCollision preliminaryCollision = pcDao.getPreliminaryCollision(localPath); if (preliminaryCollision == null) { preliminaryCollision = new PreliminaryCollision(); preliminaryCollision.setPath(localPath); preliminaryCollision = pcDao.makePersistent(preliminaryCollision); } final CryptoRepoFileDao crfDao = tx.getDao(CryptoRepoFileDao.class); if (cryptoRepoFileId != null) { CryptoRepoFile cryptoRepoFile = crfDao.getCryptoRepoFileOrFail(cryptoRepoFileId); preliminaryCollision.setCryptoRepoFile(cryptoRepoFile); } else if (file != null) { final RepoFileDao rfDao = tx.getDao(RepoFileDao.class); final RepoFile repoFile = rfDao.getRepoFile(localRepoManager.getLocalRoot(), file); if (repoFile != null) { final CryptoRepoFile cryptoRepoFile = crfDao.getCryptoRepoFileOrFail(repoFile); preliminaryCollision.setCryptoRepoFile(cryptoRepoFile); } } tx.commit(); } catch (IOException x) { throw new RuntimeException(x); } }
@Override public void delete(String path) { if (isMetaOnly()) { path = prefixPath(path); final File localRoot = getLocalRepoManager().getLocalRoot(); try (final LocalRepoTransaction transaction = getLocalRepoManager().beginWriteTransaction(); ) { final RepoFileDao repoFileDao = transaction.getDao(RepoFileDao.class); final File file = getFile(path); final RepoFile repoFile = repoFileDao.getRepoFile(localRoot, file); if (repoFile != null) deleteRepoFileRecursively(transaction, repoFile); transaction.commit(); } } else { try { super.delete(path); } catch (CollisionException x) { clearCryptoRepoFileDeleted(path); throw x; } } }
private boolean isMetaOnly() { if (metaOnly == null) { // final Iterator<UUID> repoIdIt = // getLocalRepoManager().getRemoteRepositoryId2RemoteRootMap().keySet().iterator(); // if (! repoIdIt.hasNext()) // throw new IllegalStateException("There is no remote-repository!"); // // final UUID serverRepositoryId = repoIdIt.next(); try (final LocalRepoTransaction transaction = getLocalRepoManager().beginReadTransaction(); ) { final LocalRepoStorage lrs = LocalRepoStorageFactoryRegistry.getInstance() .getLocalRepoStorageFactoryOrFail() .getLocalRepoStorageOrCreate(transaction); // final Cryptree cryptree = // CryptreeFactoryRegistry.getInstance().getCryptreeFactoryOrFail().getCryptreeOrCreate(transaction, serverRepositoryId); metaOnly = lrs.isMetaOnly(); transaction.commit(); } } return metaOnly; }