public boolean save(File file) throws IOException { FileOutputStream fos = new FileOutputStream(file); boolean ret = save(fos); fos.close(); return ret; }
void indexFile(File f) throws IOException { File meta = getMetaFileFor(f); MProperties p = MProperties.load(meta); if (p == null) p = new MProperties(); String id = p.getString("_id", null); if (id == null) { id = UUID.randomUUID().toString(); p.setString("_id", id); p.save(meta); } rememberIndex(f,id); }
private void removeIds(File file) { File meta = ((FdbCore)core).getMetaFileFor(file); MProperties p = MProperties.load(meta); if (p == null) p = new MProperties(); p.remove("_id"); try { p.save(meta); } catch (IOException e) { log().e(file,e); } }
@Override protected void doUpdate(MProperties modified) { if (!isEditable()) throw new AccessDeniedException(file); File metaFile = ((FsCore)core).getMetaFileFor(file); modified.remove("id"); try { modified.save(metaFile); } catch (IOException e) { log().w(metaFile,e); } reload(); }
@Override public OperationResult doExecuteInternal(CaoConfiguration configuration, Monitor monitor) throws CaoException { if (!canExecute(configuration)) return new NotSuccessful(getName(), "can't execute", -1); try { FsNode parent = (FsNode)configuration.getList().get(0); String rendition = configuration.getProperties().getString(UploadRenditionConfiguration.RENDITION); String path = configuration.getProperties().getString(UploadRenditionConfiguration.FILE); File file = new File(path); if (!file.exists() || !file.isFile()) throw new NotFoundException(path); File renditionFile = ((FsCore)parent.getConnection()).getContentFileFor(parent.getFile(), rendition); if (renditionFile == null) throw new MException("can't create rendition to internal file", rendition); MFile.copyFile(file, renditionFile); MProperties p = new MProperties(configuration.getProperties()); p.remove(UploadRenditionConfiguration.RENDITION); p.remove(UploadRenditionConfiguration.FILE); p.save( new File(renditionFile.getParentFile(), renditionFile.getName() + ".meta" ) ); return new Successful(getName()); } catch (Throwable t) { log().d(t); return new NotSuccessful(getName(),t.toString(),-1); } } }
p.remove(UploadRenditionConfiguration.RENDITION); p.remove(UploadRenditionConfiguration.FILE); p.save( new File(renditionFile.getParentFile(), renditionFile.getName() + ".meta" ) );
@Override protected void doUpdate(MProperties modified) { if (!isEditable()) throw new AccessDeniedException(file); File metaFile = ((FdbCore)core).getMetaFileFor(file); modified.remove("id"); try { modified.save(metaFile); } catch (IOException e) { log().w(metaFile,e); } reload(); Changes change = adaptTo(Changes.class); if (change != null) change.modified(); }