@Override public boolean renameTo(Resource dest) { return delegate.renameTo(dest); }
@Override public void handleServiceChange( ServiceInfo service, List<String> propertyNames, List<Object> oldValues, List<Object> newValues) { XStreamServiceLoader loader = findServiceLoader(service); // handle the case of a service changing workspace and move the file int i = propertyNames.indexOf("workspace"); if (i != -1) { // TODO: share code with GeoServerPersister WorkspaceInfo old = (WorkspaceInfo) oldValues.get(i); if (old != null) { WorkspaceInfo ws = (WorkspaceInfo) newValues.get(i); Resource f; try { f = dir(ws).get(loader.getFilename()); f.renameTo(dir(ws).get(loader.getFilename())); } catch (IOException e) { throw new RuntimeException(e); } } } }
if (newKSFile.renameTo(oldKSFile) == false) { String msg = "cannot rename " + newKSFile.path(); msg += "to " + oldKSFile.path();
private void removeStyle(StyleInfo s) throws IOException { Resource sld = dd.style(s); if (Resources.exists(sld)) { Resource sldBackup = dd.get(sld.path() + ".bak"); int i = 1; while (Resources.exists(sldBackup)) { sldBackup = dd.get(sld.path() + ".bak." + i++); } LOGGER.fine("Removing the SLD as well but making backup " + sldBackup.name()); sld.renameTo(sldBackup); } }
@Theory public void theoryRenamedResourcesAreEquivalent(String path) throws Exception { final Resource res = getResource(path); assumeThat(res, resource()); final byte[] expectedContent; try (InputStream in = res.in()) { expectedContent = IOUtils.toByteArray(in); } final Resource target = getUndefined(); assertThat(res.renameTo(target), is(true)); assertThat(target, resource()); final byte[] resultContent; try (InputStream in = target.in()) { resultContent = IOUtils.toByteArray(in); } assertThat(resultContent, equalTo(expectedContent)); }
@Theory public void theoryRenamedAreUndefined(String path) throws Exception { Resource res = getResource(path); assumeThat(res, defined()); Resource target = getUndefined(); assertThat(res.renameTo(target), is(true)); assertThat(res, undefined()); }
usersFile.renameTo(oldUserFile); LOGGER.info("Renamed " + usersFile.path() + " to " + oldUserFile.path());
f.renameTo(f.parent().get("catalog.xml.old"));
f.renameTo(f.parent().get("services.xml.old"));
private void rename(Resource source, Resource dest) throws IOException { // same resource? Do nothing if (source.equals(dest)) return; // different resource boolean win = System.getProperty("os.name").startsWith("Windows"); if (win && Resources.exists(dest)) { // windows does not do atomic renames, and can not rename a file if the dest file // exists if (!dest.delete()) { throw new IOException("Could not delete: " + dest.path()); } source.renameTo(dest); } else { source.renameTo(dest); } }
/** * Saves and applies the integrated GWC's GeoServer specific configuration to the {@code <data * dir>/gwc-gs.xml} file. * * @param config * @throws IOException */ public void save(final GWCConfig config) throws IOException { LOGGER.finer("Saving integrated GWC configuration"); Resource tmp = getConfigRoot().get(GWC_CONFIG_FILE + ".tmp"); XStreamPersister xmlPersister = this.persisterFactory.createXMLPersister(); configureXstream(xmlPersister.getXStream()); OutputStream out = tmp.out(); try { xmlPersister.save(config, out); } finally { out.close(); } Resource configFile = getConfigRoot().get(GWC_CONFIG_FILE); tmp.renameTo(configFile); this.config = config; LOGGER.finer("Integrated GWC configuration saved to " + configFile.path()); }
public static void saveOrUpdateRule(Rule rule) { Resource rules = DATA_DIRECTORY.get(getRulesPath()); Resource tmpRules = DATA_DIRECTORY.get(getTempRulesPath()); saveOrUpdateRule(rule, rules.in(), tmpRules.out()); rules.delete(); tmpRules.renameTo(rules); }
public static void deleteEchoParameters(String... echoParametersIds) { Resource echoParameters = DATA_DIRECTORY.get(getEchoParametersPath()); Resource tmpEchoParameters = DATA_DIRECTORY.get(getTmpEchoParametersPath()); deleteEchoParameters(echoParameters.in(), tmpEchoParameters.out(), echoParametersIds); echoParameters.delete(); tmpEchoParameters.renameTo(echoParameters); }
public static void deleteRules(String... rulesIds) { Resource rules = DATA_DIRECTORY.get(getRulesPath()); Resource tmpRules = DATA_DIRECTORY.get(getTempRulesPath()); deleteRules(rules.in(), tmpRules.out(), rulesIds); rules.delete(); tmpRules.renameTo(rules); }
public static void saveOrUpdateEchoParameter(EchoParameter echoParameter) { Resource echoParameters = DATA_DIRECTORY.get(getEchoParametersPath()); Resource tmpEchoParameters = DATA_DIRECTORY.get(getTmpEchoParametersPath()); saveOrUpdateEchoParameter(echoParameter, echoParameters.in(), tmpEchoParameters.out()); echoParameters.delete(); tmpEchoParameters.renameTo(echoParameters); }
boolean moved = source.renameTo(resource); if (!moved) { throw new RestException(
@Theory public void theoryRenamedResourcesAreEquivalent(String path) throws Exception { final Resource res = getResource(path); assumeThat(res, resource()); final byte[] expectedContent; try (InputStream in = res.in()) { expectedContent = IOUtils.toByteArray(in); } final Resource target = getUndefined(); assertThat(res.renameTo(target), is(true)); assertThat(target, resource()); final byte[] resultContent; try (InputStream in = target.in()) { resultContent = IOUtils.toByteArray(in); } assertThat(resultContent, equalTo(expectedContent)); }
@Theory public void theoryRenamedAreUndefined(String path) throws Exception { Resource res = getResource(path); assumeThat(res, defined()); Resource target = getUndefined(); assertThat(res.renameTo(target), is(true)); assertThat(res, undefined()); }
@Test public void testMove() throws Exception { put( RestBaseController.ROOT_PATH + "/resource/mydir/mynewres?operation=move", "/mydir/myres"); Resource newRes = getDataDirectory().get("/mydir/mynewres"); Assert.assertFalse(Resources.exists(myRes)); assertTrue(Resources.exists(newRes)); try (InputStream is = newRes.in()) { Assert.assertEquals(STR_MY_TEST, IOUtils.toString(is)); } newRes.renameTo(myRes); }
@Test public void testMoveDirectory() throws Exception { put(RestBaseController.ROOT_PATH + "/resource/mydir/mynewdir?operation=move", "/mydir"); put(RestBaseController.ROOT_PATH + "/resource/mynewdir?operation=move", "/mydir"); Resource newDir = getDataDirectory().get("/mynewdir"); assertTrue(Resources.exists(newDir)); assertTrue(newDir.getType() == Type.DIRECTORY); Assert.assertFalse(Resources.exists(myRes)); assertTrue(Resources.exists(getDataDirectory().get("/mynewdir/myres"))); newDir.renameTo(getDataDirectory().get("/mydir")); }