< prev index next >

src/java.base/windows/classes/sun/nio/fs/WindowsFileCopy.java

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this --- 1,7 ---- /* ! * Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this
*** 247,256 **** --- 247,267 ---- copySecurityAttributes(source, target, followLinks); } catch (IOException ignore) { } } } + // throw a DirectoryNotEmpty exception if not empty + static void ensureEmptyDir(WindowsPath dir) throws IOException { + try (WindowsDirectoryStream dirStream = + new WindowsDirectoryStream(dir, (e) -> true)) { + if (dirStream.iterator().hasNext()) { + throw new DirectoryNotEmptyException( + dir.getPathForExceptionMessage()); + } + } + } + /** * Move file from source to target */ static void move(WindowsPath source, WindowsPath target, CopyOption... options) throws IOException
*** 405,414 **** --- 416,426 ---- assert sourceAttrs.isDirectory() || sourceAttrs.isDirectoryLink(); // create new directory or directory junction try { if (sourceAttrs.isDirectory()) { + ensureEmptyDir(source); CreateDirectory(targetPath, 0L); } else { String linkTarget = WindowsLinkSupport.readLink(source); CreateSymbolicLink(targetPath, WindowsPath.addPrefixIfNeeded(linkTarget),
< prev index next >