diff --git a/LibTest/io/Link/createSync_A04_t05.dart b/LibTest/io/Link/createSync_A04_t05.dart new file mode 100644 index 0000000000..3b1e21788b --- /dev/null +++ b/LibTest/io/Link/createSync_A04_t05.dart @@ -0,0 +1,60 @@ +// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion void createSync( +/// String target, +/// {bool recursive = false} +/// ) +/// Synchronously create the link. Calling createSync on an existing link will +/// throw an exception. +/// +/// If recursive is false, the default, the link is created only if all +/// directories in its path exist. If recursive is true, all non-existing parent +/// paths are created first. The directories in the path of target are not +/// affected, unless they are also in path. +/// +/// On the Windows platform, this call will create a true symbolic link instead +/// of a junction. The link represents a file or directory and does not change +/// its type after creation. If [target] exists then the type of the link will +/// match the type [target], otherwise a file symlink is created. +/// +/// In order to create a symbolic link on Windows, Dart must be run in +/// Administrator mode or the system must have Developer Mode enabled, +/// otherwise a [FileSystemException] will be raised with +/// `ERROR_PRIVILEGE_NOT_HELD` set as the errno when this call is made. +/// +/// On other platforms, the POSIX symlink() call is used to make a symbolic link +/// containing the string target. If target is a relative path, it will be +/// interpreted relative to the directory containing the link. +/// +/// @description Checks that if `target` exists then the type of the link will +/// match the type `target`. Test [Link] pointing to a not existing entity as a +/// target (expect `file` on Windows and `notFound` on other platforms). +/// @author sgrekhov22@gmail.com + +import "dart:io"; +import "../../../Utils/expect.dart"; +import "../file_utils.dart"; + +main() { + inSandbox(_main); +} + +_main(Directory sandbox) { + Link target = getTempLinkSync( + parent: sandbox, target: getTempFilePath(parent: sandbox)); + Link link = Link(getTempFilePath(parent: sandbox)); + link.createSync(target.path); + if (Platform.isWindows) { + Expect.equals( + FileSystemEntityType.link, FileSystemEntity.typeSync(link.path)); + File file = File(link.targetSync()); + file.createSync(); + Expect.equals( + FileSystemEntityType.file, FileSystemEntity.typeSync(link.path)); + } else { + Expect.equals( + FileSystemEntityType.notFound, FileSystemEntity.typeSync(link.path)); + } +} diff --git a/LibTest/io/Link/createSync_A04_t06.dart b/LibTest/io/Link/createSync_A04_t06.dart new file mode 100644 index 0000000000..5bc13a5089 --- /dev/null +++ b/LibTest/io/Link/createSync_A04_t06.dart @@ -0,0 +1,57 @@ +// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion void createSync( +/// String target, +/// {bool recursive = false} +/// ) +/// Synchronously create the link. Calling createSync on an existing link will +/// throw an exception. +/// +/// If recursive is false, the default, the link is created only if all +/// directories in its path exist. If recursive is true, all non-existing parent +/// paths are created first. The directories in the path of target are not +/// affected, unless they are also in path. +/// +/// On the Windows platform, this call will create a true symbolic link instead +/// of a junction. The link represents a file or directory and does not change +/// its type after creation. If [target] exists then the type of the link will +/// match the type [target], otherwise a file symlink is created. +/// +/// In order to create a symbolic link on Windows, Dart must be run in +/// Administrator mode or the system must have Developer Mode enabled, +/// otherwise a [FileSystemException] will be raised with +/// `ERROR_PRIVILEGE_NOT_HELD` set as the errno when this call is made. +/// +/// On other platforms, the POSIX symlink() call is used to make a symbolic link +/// containing the string target. If target is a relative path, it will be +/// interpreted relative to the directory containing the link. +/// +/// @description Checks that if `target` does not exist then the type of the link +/// will be `file` on Windows and `notFound` on other platforms. +/// @author sgrekhov22@gmail.com + +import "dart:io"; +import "../../../Utils/expect.dart"; +import "../file_utils.dart"; + +main() { + inSandbox(_main); +} + +_main(Directory sandbox) { + Link link = Link(getTempFilePath(parent: sandbox)); + link.createSync(getTempFilePath(parent: sandbox)); + if (Platform.isWindows) { + Expect.equals( + FileSystemEntityType.link, FileSystemEntity.typeSync(link.path)); + File file = File(link.targetSync()); + file.createSync(); + Expect.equals( + FileSystemEntityType.file, FileSystemEntity.typeSync(link.path)); + } else { + Expect.equals( + FileSystemEntityType.notFound, FileSystemEntity.typeSync(link.path)); + } +} diff --git a/LibTest/io/Link/createSync_A04_t07.dart b/LibTest/io/Link/createSync_A04_t07.dart new file mode 100644 index 0000000000..5f261fff5d --- /dev/null +++ b/LibTest/io/Link/createSync_A04_t07.dart @@ -0,0 +1,68 @@ +// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion void createSync( +/// String target, +/// {bool recursive = false} +/// ) +/// Synchronously create the link. Calling createSync on an existing link will +/// throw an exception. +/// +/// If recursive is false, the default, the link is created only if all +/// directories in its path exist. If recursive is true, all non-existing parent +/// paths are created first. The directories in the path of target are not +/// affected, unless they are also in path. +/// +/// On the Windows platform, this call will create a true symbolic link instead +/// of a junction. The link represents a file or directory and does not change +/// its type after creation. If [target] exists then the type of the link will +/// match the type [target], otherwise a file symlink is created. +/// +/// In order to create a symbolic link on Windows, Dart must be run in +/// Administrator mode or the system must have Developer Mode enabled, +/// otherwise a [FileSystemException] will be raised with +/// `ERROR_PRIVILEGE_NOT_HELD` set as the errno when this call is made. +/// +/// On other platforms, the POSIX symlink() call is used to make a symbolic link +/// containing the string target. If target is a relative path, it will be +/// interpreted relative to the directory containing the link. +/// +/// @description Checks that if a link with the target directory was created and +/// then this directory was deleted and created again, then the link stays valid +/// @author sgrekhov22@gmail.com + +import "dart:io"; +import "../../../Utils/expect.dart"; +import "../file_utils.dart"; + +main() { + inSandbox(_main); +} + +_main(Directory sandbox) { + Directory target1 = getTempDirectorySync(parent: sandbox); + Link link = Link(getTempFilePath(parent: sandbox)); + link.createSync(target1.path); + Expect.equals( + FileSystemEntityType.directory, FileSystemEntity.typeSync(link.path)); + target1.deleteSync(); + if (Platform.isWindows) { + Expect.equals( + FileSystemEntityType.link, FileSystemEntity.typeSync(link.path)); + } else { + Expect.equals( + FileSystemEntityType.notFound, FileSystemEntity.typeSync(link.path)); + } + Directory target2 = Directory(target1.path); + target2.createSync(); + Expect.equals( + FileSystemEntityType.directory, FileSystemEntity.typeSync(link.path)); + target2.deleteSync(); + + Link target3 = Link(target1.path); + Directory linkTarget = getTempDirectorySync(); + target3.createSync(linkTarget.path); + Expect.equals( + FileSystemEntityType.directory, FileSystemEntity.typeSync(link.path)); +} diff --git a/LibTest/io/Link/createSync_A04_t08.dart b/LibTest/io/Link/createSync_A04_t08.dart new file mode 100644 index 0000000000..e784024a7f --- /dev/null +++ b/LibTest/io/Link/createSync_A04_t08.dart @@ -0,0 +1,79 @@ +// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion void createSync( +/// String target, +/// {bool recursive = false} +/// ) +/// Synchronously create the link. Calling createSync on an existing link will +/// throw an exception. +/// +/// If recursive is false, the default, the link is created only if all +/// directories in its path exist. If recursive is true, all non-existing parent +/// paths are created first. The directories in the path of target are not +/// affected, unless they are also in path. +/// +/// On the Windows platform, this call will create a true symbolic link instead +/// of a junction. The link represents a file or directory and does not change +/// its type after creation. If [target] exists then the type of the link will +/// match the type [target], otherwise a file symlink is created. +/// +/// In order to create a symbolic link on Windows, Dart must be run in +/// Administrator mode or the system must have Developer Mode enabled, +/// otherwise a [FileSystemException] will be raised with +/// `ERROR_PRIVILEGE_NOT_HELD` set as the errno when this call is made. +/// +/// On other platforms, the POSIX symlink() call is used to make a symbolic link +/// containing the string target. If target is a relative path, it will be +/// interpreted relative to the directory containing the link. +/// +/// @description Checks that if a link with the target directory was created and +/// then this directory was deleted and a file with the same name created, then +/// on Windows the link became invalid on other platforms it changes its type +/// @author sgrekhov22@gmail.com + +import "dart:io"; +import "../../../Utils/expect.dart"; +import "../file_utils.dart"; + +main() { + inSandbox(_main); +} + +_main(Directory sandbox) { + Directory target1 = getTempDirectorySync(parent: sandbox); + Link link = Link(getTempFilePath(parent: sandbox)); + link.createSync(target1.path); + Expect.equals( + FileSystemEntityType.directory, FileSystemEntity.typeSync(link.path)); + target1.deleteSync(); + if (Platform.isWindows) { + Expect.equals( + FileSystemEntityType.link, FileSystemEntity.typeSync(link.path)); + } else { + Expect.equals( + FileSystemEntityType.notFound, FileSystemEntity.typeSync(link.path)); + } + File target2 = File(target1.path); + target2.createSync(); + if (Platform.isWindows) { + Expect.equals( + FileSystemEntityType.link, FileSystemEntity.typeSync(link.path)); + } else { + Expect.equals( + FileSystemEntityType.file, FileSystemEntity.typeSync(link.path)); + } + target2.deleteSync(); + + Link target3 = Link(target1.path); + File linkTarget = getTempFileSync(); + target3.createSync(linkTarget.path); + if (Platform.isWindows) { + Expect.equals( + FileSystemEntityType.link, FileSystemEntity.typeSync(link.path)); + } else { + Expect.equals( + FileSystemEntityType.file, FileSystemEntity.typeSync(link.path)); + } +} diff --git a/LibTest/io/Link/createSync_A04_t09.dart b/LibTest/io/Link/createSync_A04_t09.dart new file mode 100644 index 0000000000..0fbfc8b69d --- /dev/null +++ b/LibTest/io/Link/createSync_A04_t09.dart @@ -0,0 +1,68 @@ +// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion void createSync( +/// String target, +/// {bool recursive = false} +/// ) +/// Synchronously create the link. Calling createSync on an existing link will +/// throw an exception. +/// +/// If recursive is false, the default, the link is created only if all +/// directories in its path exist. If recursive is true, all non-existing parent +/// paths are created first. The directories in the path of target are not +/// affected, unless they are also in path. +/// +/// On the Windows platform, this call will create a true symbolic link instead +/// of a junction. The link represents a file or directory and does not change +/// its type after creation. If [target] exists then the type of the link will +/// match the type [target], otherwise a file symlink is created. +/// +/// In order to create a symbolic link on Windows, Dart must be run in +/// Administrator mode or the system must have Developer Mode enabled, +/// otherwise a [FileSystemException] will be raised with +/// `ERROR_PRIVILEGE_NOT_HELD` set as the errno when this call is made. +/// +/// On other platforms, the POSIX symlink() call is used to make a symbolic link +/// containing the string target. If target is a relative path, it will be +/// interpreted relative to the directory containing the link. +/// +/// @description Checks that if a link with the target file was created and +/// then this file was deleted and created again, then the link stays valid +/// @author sgrekhov22@gmail.com + +import "dart:io"; +import "../../../Utils/expect.dart"; +import "../file_utils.dart"; + +main() { + inSandbox(_main); +} + +_main(Directory sandbox) { + File target1 = getTempFileSync(parent: sandbox); + Link link = Link(getTempFilePath(parent: sandbox)); + link.createSync(target1.path); + Expect.equals( + FileSystemEntityType.file, FileSystemEntity.typeSync(link.path)); + target1.deleteSync(); + if (Platform.isWindows) { + Expect.equals( + FileSystemEntityType.link, FileSystemEntity.typeSync(link.path)); + } else { + Expect.equals( + FileSystemEntityType.notFound, FileSystemEntity.typeSync(link.path)); + } + File target2 = File(target1.path); + target2.createSync(); + Expect.equals( + FileSystemEntityType.file, FileSystemEntity.typeSync(link.path)); + target2.deleteSync(); + + Link target3 = Link(target1.path); + File linkTarget = getTempFileSync(); + target3.createSync(linkTarget.path); + Expect.equals( + FileSystemEntityType.file, FileSystemEntity.typeSync(link.path)); +} diff --git a/LibTest/io/Link/createSync_A04_t10.dart b/LibTest/io/Link/createSync_A04_t10.dart new file mode 100644 index 0000000000..ba1fffaa29 --- /dev/null +++ b/LibTest/io/Link/createSync_A04_t10.dart @@ -0,0 +1,79 @@ +// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion void createSync( +/// String target, +/// {bool recursive = false} +/// ) +/// Synchronously create the link. Calling createSync on an existing link will +/// throw an exception. +/// +/// If recursive is false, the default, the link is created only if all +/// directories in its path exist. If recursive is true, all non-existing parent +/// paths are created first. The directories in the path of target are not +/// affected, unless they are also in path. +/// +/// On the Windows platform, this call will create a true symbolic link instead +/// of a junction. The link represents a file or directory and does not change +/// its type after creation. If [target] exists then the type of the link will +/// match the type [target], otherwise a file symlink is created. +/// +/// In order to create a symbolic link on Windows, Dart must be run in +/// Administrator mode or the system must have Developer Mode enabled, +/// otherwise a [FileSystemException] will be raised with +/// `ERROR_PRIVILEGE_NOT_HELD` set as the errno when this call is made. +/// +/// On other platforms, the POSIX symlink() call is used to make a symbolic link +/// containing the string target. If target is a relative path, it will be +/// interpreted relative to the directory containing the link. +/// +/// @description Checks that if a link with the target file was created and then +/// this file was deleted and a directory with the same name created, then +/// on Windows the link became invalid on other platforms it changes its type +/// @author sgrekhov22@gmail.com + +import "dart:io"; +import "../../../Utils/expect.dart"; +import "../file_utils.dart"; + +main() { + inSandbox(_main); +} + +_main(Directory sandbox) { + File target1 = getTempFileSync(parent: sandbox); + Link link = Link(getTempFilePath(parent: sandbox)); + link.createSync(target1.path); + Expect.equals( + FileSystemEntityType.file, FileSystemEntity.typeSync(link.path)); + target1.deleteSync(); + if (Platform.isWindows) { + Expect.equals( + FileSystemEntityType.link, FileSystemEntity.typeSync(link.path)); + } else { + Expect.equals( + FileSystemEntityType.notFound, FileSystemEntity.typeSync(link.path)); + } + Directory target2 = Directory(target1.path); + target2.createSync(); + if (Platform.isWindows) { + Expect.equals( + FileSystemEntityType.link, FileSystemEntity.typeSync(link.path)); + } else { + Expect.equals( + FileSystemEntityType.directory, FileSystemEntity.typeSync(link.path)); + } + target2.deleteSync(); + + Link target3 = Link(target1.path); + Directory linkTarget = getTempDirectorySync(); + target3.createSync(linkTarget.path); + if (Platform.isWindows) { + Expect.equals( + FileSystemEntityType.link, FileSystemEntity.typeSync(link.path)); + } else { + Expect.equals( + FileSystemEntityType.directory, FileSystemEntity.typeSync(link.path)); + } +} diff --git a/LibTest/io/Link/createSync_A04_t11.dart b/LibTest/io/Link/createSync_A04_t11.dart new file mode 100644 index 0000000000..eb69965e52 --- /dev/null +++ b/LibTest/io/Link/createSync_A04_t11.dart @@ -0,0 +1,69 @@ +// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion void createSync( +/// String target, +/// {bool recursive = false} +/// ) +/// Synchronously create the link. Calling createSync on an existing link will +/// throw an exception. +/// +/// If recursive is false, the default, the link is created only if all +/// directories in its path exist. If recursive is true, all non-existing parent +/// paths are created first. The directories in the path of target are not +/// affected, unless they are also in path. +/// +/// On the Windows platform, this call will create a true symbolic link instead +/// of a junction. The link represents a file or directory and does not change +/// its type after creation. If [target] exists then the type of the link will +/// match the type [target], otherwise a file symlink is created. +/// +/// In order to create a symbolic link on Windows, Dart must be run in +/// Administrator mode or the system must have Developer Mode enabled, +/// otherwise a [FileSystemException] will be raised with +/// `ERROR_PRIVILEGE_NOT_HELD` set as the errno when this call is made. +/// +/// On other platforms, the POSIX symlink() call is used to make a symbolic link +/// containing the string target. If target is a relative path, it will be +/// interpreted relative to the directory containing the link. +/// +/// @description Checks that if a link with the target another link pointing to +/// a directory was created and then this link was deleted and created again, +/// then the first link stays valid +/// @author sgrekhov22@gmail.com + +import "dart:io"; +import "../../../Utils/expect.dart"; +import "../file_utils.dart"; + +main() { + inSandbox(_main); +} + +_main(Directory sandbox) { + Directory linkTarget = getTempDirectorySync(parent: sandbox); + Link target1 = getTempLinkSync(parent: sandbox, target: linkTarget.path); + Link link = Link(getTempFilePath(parent: sandbox)); + link.createSync(target1.path); + Expect.equals( + FileSystemEntityType.directory, FileSystemEntity.typeSync(link.path)); + target1.deleteSync(); + if (Platform.isWindows) { + Expect.equals( + FileSystemEntityType.link, FileSystemEntity.typeSync(link.path)); + } else { + Expect.equals( + FileSystemEntityType.notFound, FileSystemEntity.typeSync(link.path)); + } + Directory target2 = Directory(target1.path); + target2.createSync(); + Expect.equals( + FileSystemEntityType.directory, FileSystemEntity.typeSync(link.path)); + target2.deleteSync(); + + Link target3 = Link(target1.path); + target3.createSync(sandbox.path); + Expect.equals( + FileSystemEntityType.directory, FileSystemEntity.typeSync(link.path)); +} diff --git a/LibTest/io/Link/createSync_A04_t12.dart b/LibTest/io/Link/createSync_A04_t12.dart new file mode 100644 index 0000000000..bade7305c1 --- /dev/null +++ b/LibTest/io/Link/createSync_A04_t12.dart @@ -0,0 +1,81 @@ +// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion void createSync( +/// String target, +/// {bool recursive = false} +/// ) +/// Synchronously create the link. Calling createSync on an existing link will +/// throw an exception. +/// +/// If recursive is false, the default, the link is created only if all +/// directories in its path exist. If recursive is true, all non-existing parent +/// paths are created first. The directories in the path of target are not +/// affected, unless they are also in path. +/// +/// On the Windows platform, this call will create a true symbolic link instead +/// of a junction. The link represents a file or directory and does not change +/// its type after creation. If [target] exists then the type of the link will +/// match the type [target], otherwise a file symlink is created. +/// +/// In order to create a symbolic link on Windows, Dart must be run in +/// Administrator mode or the system must have Developer Mode enabled, +/// otherwise a [FileSystemException] will be raised with +/// `ERROR_PRIVILEGE_NOT_HELD` set as the errno when this call is made. +/// +/// On other platforms, the POSIX symlink() call is used to make a symbolic link +/// containing the string target. If target is a relative path, it will be +/// interpreted relative to the directory containing the link. +/// +/// @description Checks that if a link with the target another link pointing to +/// a directory was created and then this link was deleted and a file with the +/// same path or link to a file created again, then the first link became +/// invalid on Windows and changes its type on other platforms +/// @author sgrekhov22@gmail.com + +import "dart:io"; +import "../../../Utils/expect.dart"; +import "../file_utils.dart"; + +main() { + inSandbox(_main); +} + +_main(Directory sandbox) { + Directory linkTarget = getTempDirectorySync(); + Link target1 = getTempLinkSync(parent: sandbox, target: linkTarget.path); + Link link = Link(getTempFilePath(parent: sandbox)); + link.createSync(target1.path); + Expect.equals( + FileSystemEntityType.directory, FileSystemEntity.typeSync(link.path)); + target1.deleteSync(); + if (Platform.isWindows) { + Expect.equals( + FileSystemEntityType.link, FileSystemEntity.typeSync(link.path)); + } else { + Expect.equals( + FileSystemEntityType.notFound, FileSystemEntity.typeSync(link.path)); + } + File target2 = File(target1.path); + target2.createSync(); + if (Platform.isWindows) { + Expect.equals( + FileSystemEntityType.link, FileSystemEntity.typeSync(link.path)); + } else { + Expect.equals( + FileSystemEntityType.file, FileSystemEntity.typeSync(link.path)); + } + target2.deleteSync(); + + Link target3 = Link(target1.path); + File linkTarget3 = getTempFileSync(); + target3.createSync(linkTarget3.path); + if (Platform.isWindows) { + Expect.equals( + FileSystemEntityType.link, FileSystemEntity.typeSync(link.path)); + } else { + Expect.equals( + FileSystemEntityType.file, FileSystemEntity.typeSync(link.path)); + } +} diff --git a/LibTest/io/Link/createSync_A04_t13.dart b/LibTest/io/Link/createSync_A04_t13.dart new file mode 100644 index 0000000000..9b73b729f7 --- /dev/null +++ b/LibTest/io/Link/createSync_A04_t13.dart @@ -0,0 +1,70 @@ +// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion void createSync( +/// String target, +/// {bool recursive = false} +/// ) +/// Synchronously create the link. Calling createSync on an existing link will +/// throw an exception. +/// +/// If recursive is false, the default, the link is created only if all +/// directories in its path exist. If recursive is true, all non-existing parent +/// paths are created first. The directories in the path of target are not +/// affected, unless they are also in path. +/// +/// On the Windows platform, this call will create a true symbolic link instead +/// of a junction. The link represents a file or directory and does not change +/// its type after creation. If [target] exists then the type of the link will +/// match the type [target], otherwise a file symlink is created. +/// +/// In order to create a symbolic link on Windows, Dart must be run in +/// Administrator mode or the system must have Developer Mode enabled, +/// otherwise a [FileSystemException] will be raised with +/// `ERROR_PRIVILEGE_NOT_HELD` set as the errno when this call is made. +/// +/// On other platforms, the POSIX symlink() call is used to make a symbolic link +/// containing the string target. If target is a relative path, it will be +/// interpreted relative to the directory containing the link. +/// +/// @description Checks that if a link with the target another link pointing to +/// a file was created and then this link was deleted and created again, then +/// the link stays valid +/// @author sgrekhov22@gmail.com + +import "dart:io"; +import "../../../Utils/expect.dart"; +import "../file_utils.dart"; + +main() { + inSandbox(_main); +} + +_main(Directory sandbox) { + File linkTarget = getTempFileSync(parent: sandbox); + Link target1 = getTempLinkSync(parent: sandbox, target: linkTarget.path); + Link link = Link(getTempFilePath(parent: sandbox)); + link.createSync(target1.path); + Expect.equals( + FileSystemEntityType.file, FileSystemEntity.typeSync(link.path)); + target1.deleteSync(); + if (Platform.isWindows) { + Expect.equals( + FileSystemEntityType.link, FileSystemEntity.typeSync(link.path)); + } else { + Expect.equals(FileSystemEntityType.notFound, + FileSystemEntity.typeSync(link.path)); + } + File target2 = File(target1.path); + target2.createSync(); + Expect.equals(FileSystemEntityType.file, + FileSystemEntity.typeSync(link.path)); + target2.deleteSync(); + + Link target3 = Link(target1.path); + File linkTarget3 = getTempFileSync(); + target3.createSync(linkTarget3.path); + Expect.equals(FileSystemEntityType.file, + FileSystemEntity.typeSync(link.path)); +} diff --git a/LibTest/io/Link/createSync_A04_t14.dart b/LibTest/io/Link/createSync_A04_t14.dart new file mode 100644 index 0000000000..41e160390a --- /dev/null +++ b/LibTest/io/Link/createSync_A04_t14.dart @@ -0,0 +1,81 @@ +// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion void createSync( +/// String target, +/// {bool recursive = false} +/// ) +/// Synchronously create the link. Calling createSync on an existing link will +/// throw an exception. +/// +/// If recursive is false, the default, the link is created only if all +/// directories in its path exist. If recursive is true, all non-existing parent +/// paths are created first. The directories in the path of target are not +/// affected, unless they are also in path. +/// +/// On the Windows platform, this call will create a true symbolic link instead +/// of a junction. The link represents a file or directory and does not change +/// its type after creation. If [target] exists then the type of the link will +/// match the type [target], otherwise a file symlink is created. +/// +/// In order to create a symbolic link on Windows, Dart must be run in +/// Administrator mode or the system must have Developer Mode enabled, +/// otherwise a [FileSystemException] will be raised with +/// `ERROR_PRIVILEGE_NOT_HELD` set as the errno when this call is made. +/// +/// On other platforms, the POSIX symlink() call is used to make a symbolic link +/// containing the string target. If target is a relative path, it will be +/// interpreted relative to the directory containing the link. +/// +/// @description Checks that if a link with the target another link pointing to +/// a file was created and then this link was deleted and a directory with the +/// same name created, then on Windows the link became invalid on other +/// platforms it changes its type +/// @author sgrekhov22@gmail.com + +import "dart:io"; +import "../../../Utils/expect.dart"; +import "../file_utils.dart"; + +main() { + inSandbox(_main); +} + +_main(Directory sandbox) { + File linkTarget = getTempFileSync(parent: sandbox); + Link target1 = getTempLinkSync(parent: sandbox, target: linkTarget.path); + Link link = Link(getTempFilePath(parent: sandbox)); + link.createSync(target1.path); + Expect.equals(FileSystemEntityType.file, + FileSystemEntity.typeSync(link.path)); + target1.deleteSync(); + if (Platform.isWindows) { + Expect.equals( + FileSystemEntityType.link, FileSystemEntity.typeSync(link.path)); + } else { + Expect.equals(FileSystemEntityType.notFound, + FileSystemEntity.typeSync(link.path)); + } + Directory target2 = Directory(target1.path); + target2.createSync(); + if (Platform.isWindows) { + Expect.equals( + FileSystemEntityType.link, FileSystemEntity.typeSync(link.path)); + } else { + Expect.equals(FileSystemEntityType.directory, + FileSystemEntity.typeSync(link.path)); + } + target2.deleteSync(); + + Link target3 = Link(target1.path); + Directory linkTarget3 = getTempDirectorySync(); + target3.createSync(linkTarget3.path); + if (Platform.isWindows) { + Expect.equals( + FileSystemEntityType.link, FileSystemEntity.typeSync(link.path)); + } else { + Expect.equals(FileSystemEntityType.directory, + FileSystemEntity.typeSync(link.path)); + } +} diff --git a/LibTest/io/Link/createSync_A04_t15.dart b/LibTest/io/Link/createSync_A04_t15.dart new file mode 100644 index 0000000000..8e5ce72513 --- /dev/null +++ b/LibTest/io/Link/createSync_A04_t15.dart @@ -0,0 +1,65 @@ +// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion void createSync( +/// String target, +/// {bool recursive = false} +/// ) +/// Synchronously create the link. Calling createSync on an existing link will +/// throw an exception. +/// +/// If recursive is false, the default, the link is created only if all +/// directories in its path exist. If recursive is true, all non-existing parent +/// paths are created first. The directories in the path of target are not +/// affected, unless they are also in path. +/// +/// On the Windows platform, this call will create a true symbolic link instead +/// of a junction. The link represents a file or directory and does not change +/// its type after creation. If [target] exists then the type of the link will +/// match the type [target], otherwise a file symlink is created. +/// +/// In order to create a symbolic link on Windows, Dart must be run in +/// Administrator mode or the system must have Developer Mode enabled, +/// otherwise a [FileSystemException] will be raised with +/// `ERROR_PRIVILEGE_NOT_HELD` set as the errno when this call is made. +/// +/// On other platforms, the POSIX symlink() call is used to make a symbolic link +/// containing the string target. If target is a relative path, it will be +/// interpreted relative to the directory containing the link. +/// +/// @description Checks that if a link with the not existing target was created +/// and then a file on the link's target was created, then the link became valid +/// @author sgrekhov22@gmail.com + +import "dart:io"; +import "../../../Utils/expect.dart"; +import "../file_utils.dart"; + +main() { + inSandbox(_main); +} + +_main(Directory sandbox) { + String linkTarget = getTempFilePath(parent: sandbox); + Link link = Link(getTempFilePath(parent: sandbox)); + link.createSync(linkTarget); + if (Platform.isWindows) { + Expect.equals( + FileSystemEntityType.link, FileSystemEntity.typeSync(link.path)); + } else { + Expect.equals( + FileSystemEntityType.notFound, FileSystemEntity.typeSync(link.path)); + } + File target2 = File(linkTarget); + target2.createSync(); + Expect.equals( + FileSystemEntityType.file, FileSystemEntity.typeSync(link.path)); + target2.deleteSync(); + + Link target3 = Link(linkTarget); + File _linkTarget = getTempFileSync(); + target3.createSync(_linkTarget.path); + Expect.equals( + FileSystemEntityType.file, FileSystemEntity.typeSync(link.path)); +} diff --git a/LibTest/io/Link/createSync_A04_t16.dart b/LibTest/io/Link/createSync_A04_t16.dart new file mode 100644 index 0000000000..4afb8658a7 --- /dev/null +++ b/LibTest/io/Link/createSync_A04_t16.dart @@ -0,0 +1,75 @@ +// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion void createSync( +/// String target, +/// {bool recursive = false} +/// ) +/// Synchronously create the link. Calling createSync on an existing link will +/// throw an exception. +/// +/// If recursive is false, the default, the link is created only if all +/// directories in its path exist. If recursive is true, all non-existing parent +/// paths are created first. The directories in the path of target are not +/// affected, unless they are also in path. +/// +/// On the Windows platform, this call will create a true symbolic link instead +/// of a junction. The link represents a file or directory and does not change +/// its type after creation. If [target] exists then the type of the link will +/// match the type [target], otherwise a file symlink is created. +/// +/// In order to create a symbolic link on Windows, Dart must be run in +/// Administrator mode or the system must have Developer Mode enabled, +/// otherwise a [FileSystemException] will be raised with +/// `ERROR_PRIVILEGE_NOT_HELD` set as the errno when this call is made. +/// +/// On other platforms, the POSIX symlink() call is used to make a symbolic link +/// containing the string target. If target is a relative path, it will be +/// interpreted relative to the directory containing the link. +/// +/// @description Checks that if a link with the not existing target was created +/// and then a directory on the link's target was created, then the link become +/// invalid on Windows and changes its type on other platforms +/// @author sgrekhov22@gmail.com + +import "dart:io"; +import "../../../Utils/expect.dart"; +import "../file_utils.dart"; + +main() { + inSandbox(_main); +} + +_main(Directory sandbox) { + String linkTarget = getTempFilePath(parent: sandbox); + Link link = Link(getTempFilePath(parent: sandbox)); + link.createSync(linkTarget); + if (Platform.isWindows) { + Expect.equals( + FileSystemEntityType.link, FileSystemEntity.typeSync(link.path)); + } else { + Expect.equals( + FileSystemEntityType.notFound, FileSystemEntity.typeSync(link.path)); + } + Directory target2 = Directory(linkTarget); + target2.createSync(); + if (Platform.isWindows) { + Expect.equals( + FileSystemEntityType.link, FileSystemEntity.typeSync(link.path)); + } else { + Expect.equals( + FileSystemEntityType.directory, FileSystemEntity.typeSync(link.path)); + } + target2.deleteSync(); + + Link target3 = Link(linkTarget); + target3.createSync(sandbox.path); + if (Platform.isWindows) { + Expect.equals( + FileSystemEntityType.link, FileSystemEntity.typeSync(link.path)); + } else { + Expect.equals( + FileSystemEntityType.directory, FileSystemEntity.typeSync(link.path)); + } +} diff --git a/LibTest/io/Link/createSync_A05_t01.dart b/LibTest/io/Link/createSync_A05_t01.dart index 934233ef8a..e1f2d94ab8 100644 --- a/LibTest/io/Link/createSync_A05_t01.dart +++ b/LibTest/io/Link/createSync_A05_t01.dart @@ -3,35 +3,33 @@ // BSD-style license that can be found in the LICENSE file. /// @assertion void createSync( -/// String target, { -/// bool recursive: false -/// }) +/// String target, +/// {bool recursive = false} +/// ) /// Synchronously create the link. Calling createSync on an existing link will /// throw an exception. /// -/// If recursive is false, the default, the link is created only if all -/// directories in its path exist. If recursive is true, all non-existing path -/// components are created. The directories in the path of target are not -/// affected, unless they are also in path. +/// If recursive is false, the default, the link is created only if all +/// directories in its path exist. If recursive is true, all non-existing parent +/// paths are created first. The directories in the path of target are not +/// affected, unless they are also in path. /// -/// On the Windows platform, this call will create a true symbolic link instead -/// of a Junction. In order to create a symbolic link on Windows, Dart must be -/// run in Administrator mode or the system must have Developer Mode enabled, -/// otherwise a FileSystemException will be raised with ERROR_PRIVILEGE_NOT_HELD -/// set as the errno when this call is made. +/// On the Windows platform, this call will create a true symbolic link instead +/// of a junction. The link represents a file or directory and does not change +/// its type after creation. If [target] exists then the type of the link will +/// match the type [target], otherwise a file symlink is created. /// -/// On other platforms, the posix symlink() call is used to make a symbolic link -/// containing the string target. If target is a relative path, it will be -/// interpreted relative to the directory containing the link. -/// @description Checks that on the Windows platform relative paths to the target -/// is not converted to absolute paths (as it was in the past) -/// -/// @note The test should run with the Administrator priveleges on Windows. -/// Dart API Spec reads: /// In order to create a symbolic link on Windows, Dart must be run in -/// Administrator mode or the system must have Developer Mode enabled, otherwise -/// a FileSystemException will be raised with ERROR_PRIVILEGE_NOT_HELD set as -/// the errno when this call is made. +/// Administrator mode or the system must have Developer Mode enabled, +/// otherwise a [FileSystemException] will be raised with +/// `ERROR_PRIVILEGE_NOT_HELD` set as the errno when this call is made. +/// +/// On other platforms, the POSIX symlink() call is used to make a symbolic link +/// containing the string target. If target is a relative path, it will be +/// interpreted relative to the directory containing the link. +/// +/// @description Checks that on the Windows platform relative paths to the +/// target is not converted to absolute paths (as it was in the past) /// /// @author sgrekhov@unipro.ru diff --git a/LibTest/io/Link/createSync_A06_t01.dart b/LibTest/io/Link/createSync_A06_t01.dart index e4faa06870..8d0759f275 100644 --- a/LibTest/io/Link/createSync_A06_t01.dart +++ b/LibTest/io/Link/createSync_A06_t01.dart @@ -3,48 +3,66 @@ // BSD-style license that can be found in the LICENSE file. /// @assertion void createSync( -/// String target, { -/// bool recursive: false -/// }) +/// String target, +/// {bool recursive = false} +/// ) /// Synchronously create the link. Calling createSync on an existing link will /// throw an exception. /// -/// If recursive is false, the default, the link is created only if all -/// directories in its path exist. If recursive is true, all non-existing path -/// components are created. The directories in the path of target are not -/// affected, unless they are also in path. +/// If recursive is false, the default, the link is created only if all +/// directories in its path exist. If recursive is true, all non-existing parent +/// paths are created first. The directories in the path of target are not +/// affected, unless they are also in path. /// -/// On the Windows platform, this will only work with directories, and the -/// target directory must exist. The link will be created as a Junction. Only -/// absolute links will be created, and relative paths to the target will be -/// converted to absolute paths. +/// On the Windows platform, this call will create a true symbolic link instead +/// of a junction. The link represents a file or directory and does not change +/// its type after creation. If [target] exists then the type of the link will +/// match the type [target], otherwise a file symlink is created. /// -/// On other platforms, the posix symlink() call is used to make a symbolic link -/// containing the string target. If target is a relative path, it will be -/// interpreted relative to the directory containing the link. -/// @description Checks that on non-Windows platforms only absolute links will be -/// created, and relative paths to the target will be interpreted relative to the -/// directory containing the link. +/// In order to create a symbolic link on Windows, Dart must be run in +/// Administrator mode or the system must have Developer Mode enabled, +/// otherwise a [FileSystemException] will be raised with +/// `ERROR_PRIVILEGE_NOT_HELD` set as the errno when this call is made. +/// +/// On other platforms, the POSIX symlink() call is used to make a symbolic link +/// containing the string target. If target is a relative path, it will be +/// interpreted relative to the directory containing the link. +/// +/// @description Checks that relative paths to the target will be interpreted +/// relative to the directory containing the link. Test relative path to +/// [Directory] /// @author sgrekhov@unipro.ru +/// @issue 53689 import "dart:io"; import "../../../Utils/expect.dart"; import "../file_utils.dart"; -main() async { - await inSandbox(_main); +main() { + inSandbox(_main); } -_main(Directory sandbox) async { - if (!Platform.isWindows) { - Directory dir = getTempDirectorySync(parent: sandbox); - String dirName = getTempDirectoryName(); - Directory target = new Directory(dir.path + - Platform.pathSeparator + dirName); - target.createSync(); - Link link = new Link(dir.path + Platform.pathSeparator + - getTempFileName(extension: "lnk")); - link.createSync(dirName); - Expect.equals(dirName, link.targetSync()); +_main(Directory sandbox) { + String dirName = getTempDirectoryName(); + Directory target = Directory(sandbox.path + Platform.pathSeparator + dirName); + target.createSync(); + Link link = Link(sandbox.path + + Platform.pathSeparator + + getTempFileName(extension: "lnk")); + link.createSync(dirName); + Expect.equals(dirName, link.targetSync()); + Expect.equals( + FileSystemEntityType.directory, FileSystemEntity.typeSync(link.path)); + // Now create a directory and move the link into it. Its relative target + // should point to a not existing entity after it + Directory dir = getTempDirectorySync(parent: sandbox); + Link moved = link.renameSync(dir.path + Platform.pathSeparator + "moved.lnk"); + Expect.equals(dirName, moved.targetSync()); + if (Platform.isWindows) { + Expect.equals( + FileSystemEntityType.link, FileSystemEntity.typeSync(moved.path)); + } else { + Expect.equals( + FileSystemEntityType.notFound, FileSystemEntity.typeSync(moved.path)); } } diff --git a/LibTest/io/Link/createSync_A06_t02.dart b/LibTest/io/Link/createSync_A06_t02.dart new file mode 100644 index 0000000000..f1288801cd --- /dev/null +++ b/LibTest/io/Link/createSync_A06_t02.dart @@ -0,0 +1,66 @@ +// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion void createSync( +/// String target, +/// {bool recursive = false} +/// ) +/// Synchronously create the link. Calling createSync on an existing link will +/// throw an exception. +/// +/// If recursive is false, the default, the link is created only if all +/// directories in its path exist. If recursive is true, all non-existing parent +/// paths are created first. The directories in the path of target are not +/// affected, unless they are also in path. +/// +/// On the Windows platform, this call will create a true symbolic link instead +/// of a junction. The link represents a file or directory and does not change +/// its type after creation. If [target] exists then the type of the link will +/// match the type [target], otherwise a file symlink is created. +/// +/// In order to create a symbolic link on Windows, Dart must be run in +/// Administrator mode or the system must have Developer Mode enabled, +/// otherwise a [FileSystemException] will be raised with +/// `ERROR_PRIVILEGE_NOT_HELD` set as the errno when this call is made. +/// +/// On other platforms, the POSIX symlink() call is used to make a symbolic link +/// containing the string target. If target is a relative path, it will be +/// interpreted relative to the directory containing the link. +/// +/// @description Checks that relative paths to the target will be interpreted +/// relative to the directory containing the link. Test relative path to [File] +/// @author sgrekhov22@gmail.com + +import "dart:io"; +import "../../../Utils/expect.dart"; +import "../file_utils.dart"; + +main() { + inSandbox(_main); +} + +_main(Directory sandbox) { + String fileName = getTempFileName(); + File target = new File(sandbox.path + Platform.pathSeparator + fileName); + target.createSync(); + Link link = new Link(sandbox.path + + Platform.pathSeparator + + getTempFileName(extension: "lnk")); + link.createSync(fileName); + Expect.equals(fileName, link.targetSync()); + Expect.equals( + FileSystemEntityType.file, FileSystemEntity.typeSync(link.path)); + // Now create a directory and move the link into it. Its relative target + // should point to a not existing entity after it + Directory dir = getTempDirectorySync(parent: sandbox); + Link moved = link.renameSync(dir.path + Platform.pathSeparator + "moved.lnk"); + Expect.equals(fileName, moved.targetSync()); + if (Platform.isWindows) { + Expect.equals( + FileSystemEntityType.link, FileSystemEntity.typeSync(moved.path)); + } else { + Expect.equals( + FileSystemEntityType.notFound, FileSystemEntity.typeSync(moved.path)); + } +} diff --git a/LibTest/io/Link/createSync_A06_t03.dart b/LibTest/io/Link/createSync_A06_t03.dart new file mode 100644 index 0000000000..fbf1154778 --- /dev/null +++ b/LibTest/io/Link/createSync_A06_t03.dart @@ -0,0 +1,68 @@ +// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion void createSync( +/// String target, +/// {bool recursive = false} +/// ) +/// Synchronously create the link. Calling createSync on an existing link will +/// throw an exception. +/// +/// If recursive is false, the default, the link is created only if all +/// directories in its path exist. If recursive is true, all non-existing parent +/// paths are created first. The directories in the path of target are not +/// affected, unless they are also in path. +/// +/// On the Windows platform, this call will create a true symbolic link instead +/// of a junction. The link represents a file or directory and does not change +/// its type after creation. If [target] exists then the type of the link will +/// match the type [target], otherwise a file symlink is created. +/// +/// In order to create a symbolic link on Windows, Dart must be run in +/// Administrator mode or the system must have Developer Mode enabled, +/// otherwise a [FileSystemException] will be raised with +/// `ERROR_PRIVILEGE_NOT_HELD` set as the errno when this call is made. +/// +/// On other platforms, the POSIX symlink() call is used to make a symbolic link +/// containing the string target. If target is a relative path, it will be +/// interpreted relative to the directory containing the link. +/// +/// @description Checks that relative paths to the target will be interpreted +/// relative to the directory containing the link. Test relative path to [Link] +/// pointing to [Directory] +/// @author sgrekhov22@gmail.com +/// @issue 53689 + +import "dart:io"; +import "../../../Utils/expect.dart"; +import "../file_utils.dart"; + +main() { + inSandbox(_main); +} + +_main(Directory sandbox) { + String linkName = getTempFileName(); + Link target = new Link(sandbox.path + Platform.pathSeparator + linkName); + target.createSync(sandbox.path); + Link link = new Link(sandbox.path + + Platform.pathSeparator + + getTempFileName(extension: "lnk")); + link.createSync(linkName); + Expect.equals(linkName, link.targetSync()); + Expect.equals( + FileSystemEntityType.directory, FileSystemEntity.typeSync(link.path)); + // Now create a directory and move the link into it. Its relative target + // should point to a not existing entity after it + Directory dir = getTempDirectorySync(parent: sandbox); + Link moved = link.renameSync(dir.path + Platform.pathSeparator + "moved.lnk"); + Expect.equals(linkName, moved.targetSync()); + if (Platform.isWindows) { + Expect.equals( + FileSystemEntityType.link, FileSystemEntity.typeSync(moved.path)); + } else { + Expect.equals( + FileSystemEntityType.notFound, FileSystemEntity.typeSync(moved.path)); + } +} diff --git a/LibTest/io/Link/createSync_A06_t04.dart b/LibTest/io/Link/createSync_A06_t04.dart new file mode 100644 index 0000000000..ff2f939d78 --- /dev/null +++ b/LibTest/io/Link/createSync_A06_t04.dart @@ -0,0 +1,68 @@ +// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion void createSync( +/// String target, +/// {bool recursive = false} +/// ) +/// Synchronously create the link. Calling createSync on an existing link will +/// throw an exception. +/// +/// If recursive is false, the default, the link is created only if all +/// directories in its path exist. If recursive is true, all non-existing parent +/// paths are created first. The directories in the path of target are not +/// affected, unless they are also in path. +/// +/// On the Windows platform, this call will create a true symbolic link instead +/// of a junction. The link represents a file or directory and does not change +/// its type after creation. If [target] exists then the type of the link will +/// match the type [target], otherwise a file symlink is created. +/// +/// In order to create a symbolic link on Windows, Dart must be run in +/// Administrator mode or the system must have Developer Mode enabled, +/// otherwise a [FileSystemException] will be raised with +/// `ERROR_PRIVILEGE_NOT_HELD` set as the errno when this call is made. +/// +/// On other platforms, the POSIX symlink() call is used to make a symbolic link +/// containing the string target. If target is a relative path, it will be +/// interpreted relative to the directory containing the link. +/// +/// @description Checks that relative paths to the target will be interpreted +/// relative to the directory containing the link. Test relative path to [Link] +/// pointing to [File] +/// @author sgrekhov22@gmail.com + +import "dart:io"; +import "../../../Utils/expect.dart"; +import "../file_utils.dart"; + +main() { + inSandbox(_main); +} + +_main(Directory sandbox) { + String linkName = getTempFileName(); + File file = getTempFileSync(parent: sandbox); + Link target = Link(sandbox.path + Platform.pathSeparator + linkName); + target.createSync(file.path); + Link link = Link(sandbox.path + + Platform.pathSeparator + + getTempFileName(extension: "lnk")); + link.createSync(linkName); + Expect.equals(linkName, link.targetSync()); + Expect.equals( + FileSystemEntityType.file, FileSystemEntity.typeSync(link.path)); + // Now create a directory and move the link into it. Its relative target + // should point to a not existing entity after it + Directory dir = getTempDirectorySync(parent: sandbox); + Link moved = link.renameSync(dir.path + Platform.pathSeparator + "moved.lnk"); + Expect.equals(linkName, moved.targetSync()); + if (Platform.isWindows) { + Expect.equals( + FileSystemEntityType.link, FileSystemEntity.typeSync(moved.path)); + } else { + Expect.equals( + FileSystemEntityType.notFound, FileSystemEntity.typeSync(moved.path)); + } +} diff --git a/LibTest/io/Link/createSync_A06_t05.dart b/LibTest/io/Link/createSync_A06_t05.dart new file mode 100644 index 0000000000..f7f11a26b0 --- /dev/null +++ b/LibTest/io/Link/createSync_A06_t05.dart @@ -0,0 +1,70 @@ +// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion void createSync( +/// String target, +/// {bool recursive = false} +/// ) +/// Synchronously create the link. Calling createSync on an existing link will +/// throw an exception. +/// +/// If recursive is false, the default, the link is created only if all +/// directories in its path exist. If recursive is true, all non-existing parent +/// paths are created first. The directories in the path of target are not +/// affected, unless they are also in path. +/// +/// On the Windows platform, this call will create a true symbolic link instead +/// of a junction. The link represents a file or directory and does not change +/// its type after creation. If [target] exists then the type of the link will +/// match the type [target], otherwise a file symlink is created. +/// +/// In order to create a symbolic link on Windows, Dart must be run in +/// Administrator mode or the system must have Developer Mode enabled, +/// otherwise a [FileSystemException] will be raised with +/// `ERROR_PRIVILEGE_NOT_HELD` set as the errno when this call is made. +/// +/// On other platforms, the POSIX symlink() call is used to make a symbolic link +/// containing the string target. If target is a relative path, it will be +/// interpreted relative to the directory containing the link. +/// +/// @description Checks that relative paths to the target will be interpreted +/// relative to the directory containing the link. Test relative path to [Link] +/// pointing to a not existing entity +/// @author sgrekhov22@gmail.com + +import "dart:io"; +import "../../../Utils/expect.dart"; +import "../file_utils.dart"; + +main() { + inSandbox(_main); +} + +_main(Directory sandbox) { + String notExisting = getTempFileName(); + String target = getTempFileName(extension: "lnk"); + getTempLinkSync(parent: sandbox, target: notExisting, name: target); + Link link = Link(sandbox.path + + Platform.pathSeparator + + getTempFileName(extension: "lnk")); + link.createSync(target); + Expect.equals(target, link.targetSync()); + if (Platform.isWindows) { + Expect.equals( + FileSystemEntityType.link, FileSystemEntity.typeSync(link.path)); + } else { + Expect.equals( + FileSystemEntityType.notFound, FileSystemEntity.typeSync(link.path)); + } + // Now create a directory and into it the file with the name as link's + // target. Then move the link into the directory. Its relative target should + // point to that file after it + Directory dir = getTempDirectorySync(parent: sandbox); + File file = File(dir.path + Platform.pathSeparator + target); + file.createSync(); + Link moved = link.renameSync(dir.path + Platform.pathSeparator + "moved.lnk"); + Expect.equals(target, moved.targetSync()); + Expect.equals( + FileSystemEntityType.file, FileSystemEntity.typeSync(moved.path)); +} diff --git a/LibTest/io/Link/createSync_A06_t06.dart b/LibTest/io/Link/createSync_A06_t06.dart new file mode 100644 index 0000000000..a09a7f636c --- /dev/null +++ b/LibTest/io/Link/createSync_A06_t06.dart @@ -0,0 +1,77 @@ +// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion void createSync( +/// String target, +/// {bool recursive = false} +/// ) +/// Synchronously create the link. Calling createSync on an existing link will +/// throw an exception. +/// +/// If recursive is false, the default, the link is created only if all +/// directories in its path exist. If recursive is true, all non-existing parent +/// paths are created first. The directories in the path of target are not +/// affected, unless they are also in path. +/// +/// On the Windows platform, this call will create a true symbolic link instead +/// of a junction. The link represents a file or directory and does not change +/// its type after creation. If [target] exists then the type of the link will +/// match the type [target], otherwise a file symlink is created. +/// +/// In order to create a symbolic link on Windows, Dart must be run in +/// Administrator mode or the system must have Developer Mode enabled, +/// otherwise a [FileSystemException] will be raised with +/// `ERROR_PRIVILEGE_NOT_HELD` set as the errno when this call is made. +/// +/// On other platforms, the POSIX symlink() call is used to make a symbolic link +/// containing the string target. If target is a relative path, it will be +/// interpreted relative to the directory containing the link. +/// +/// @description Checks that relative paths to the target will be interpreted +/// relative to the directory containing the link. Test relative path to [Link] +/// pointing to a not existing entity +/// @author sgrekhov22@gmail.com + +import "dart:io"; +import "../../../Utils/expect.dart"; +import "../file_utils.dart"; + +main() { + inSandbox(_main); +} + +_main(Directory sandbox) { + String notExisting = getTempFileName(); + String target = getTempFileName(extension: "lnk"); + Link targetLink = + getTempLinkSync(parent: sandbox, target: notExisting, name: target); + Link link = Link(sandbox.path + + Platform.pathSeparator + + getTempFileName(extension: "lnk")); + link.createSync(target); + Expect.equals(target, link.targetSync()); + if (Platform.isWindows) { + Expect.equals( + FileSystemEntityType.link, FileSystemEntity.typeSync(link.path)); + } else { + Expect.equals( + FileSystemEntityType.notFound, FileSystemEntity.typeSync(link.path)); + } + // Now create a directory and into it another directory with the name as + // link's target. Then move the link into the first directory. Its relative + // target should point to the second directory after it (except Windows) + Directory dir1 = getTempDirectorySync(parent: sandbox); + Directory dir2 = Directory(dir1.path + Platform.pathSeparator + target); + dir2.createSync(); + Link moved = + link.renameSync(dir1.path + Platform.pathSeparator + "moved.lnk"); + Expect.equals(target, moved.targetSync()); + if (Platform.isWindows) { + Expect.equals( + FileSystemEntityType.link, FileSystemEntity.typeSync(moved.path)); + } else { + Expect.equals( + FileSystemEntityType.directory, FileSystemEntity.typeSync(moved.path)); + } +} diff --git a/LibTest/io/Link/createSync_A06_t07.dart b/LibTest/io/Link/createSync_A06_t07.dart new file mode 100644 index 0000000000..a68db79e1c --- /dev/null +++ b/LibTest/io/Link/createSync_A06_t07.dart @@ -0,0 +1,68 @@ +// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion void createSync( +/// String target, +/// {bool recursive = false} +/// ) +/// Synchronously create the link. Calling createSync on an existing link will +/// throw an exception. +/// +/// If recursive is false, the default, the link is created only if all +/// directories in its path exist. If recursive is true, all non-existing parent +/// paths are created first. The directories in the path of target are not +/// affected, unless they are also in path. +/// +/// On the Windows platform, this call will create a true symbolic link instead +/// of a junction. The link represents a file or directory and does not change +/// its type after creation. If [target] exists then the type of the link will +/// match the type [target], otherwise a file symlink is created. +/// +/// In order to create a symbolic link on Windows, Dart must be run in +/// Administrator mode or the system must have Developer Mode enabled, +/// otherwise a [FileSystemException] will be raised with +/// `ERROR_PRIVILEGE_NOT_HELD` set as the errno when this call is made. +/// +/// On other platforms, the POSIX symlink() call is used to make a symbolic link +/// containing the string target. If target is a relative path, it will be +/// interpreted relative to the directory containing the link. +/// +/// @description Checks that relative paths to the target will be interpreted +/// relative to the directory containing the link. Test relative path to a not +/// existing entity +/// @author sgrekhov22@gmail.com + +import "dart:io"; +import "../../../Utils/expect.dart"; +import "../file_utils.dart"; + +main() { + inSandbox(_main); +} + +_main(Directory sandbox) { + String target = getTempFileName(); + Link link = Link(sandbox.path + + Platform.pathSeparator + + getTempFileName(extension: "lnk")); + link.createSync(target); + Expect.equals(target, link.targetSync()); + if (Platform.isWindows) { + Expect.equals( + FileSystemEntityType.link, FileSystemEntity.typeSync(link.path)); + } else { + Expect.equals( + FileSystemEntityType.notFound, FileSystemEntity.typeSync(link.path)); + } + // Now create a directory and into it the file with the name as link's + // target. Then move the link into the directory. Its relative target should + // point to that file after it + Directory dir = getTempDirectorySync(parent: sandbox); + File file = File(dir.path + Platform.pathSeparator + target); + file.createSync(); + Link moved = link.renameSync(dir.path + Platform.pathSeparator + "moved.lnk"); + Expect.equals(target, moved.targetSync()); + Expect.equals( + FileSystemEntityType.file, FileSystemEntity.typeSync(moved.path)); +} diff --git a/LibTest/io/Link/createSync_A06_t08.dart b/LibTest/io/Link/createSync_A06_t08.dart new file mode 100644 index 0000000000..af521a7d06 --- /dev/null +++ b/LibTest/io/Link/createSync_A06_t08.dart @@ -0,0 +1,74 @@ +// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion void createSync( +/// String target, +/// {bool recursive = false} +/// ) +/// Synchronously create the link. Calling createSync on an existing link will +/// throw an exception. +/// +/// If recursive is false, the default, the link is created only if all +/// directories in its path exist. If recursive is true, all non-existing parent +/// paths are created first. The directories in the path of target are not +/// affected, unless they are also in path. +/// +/// On the Windows platform, this call will create a true symbolic link instead +/// of a junction. The link represents a file or directory and does not change +/// its type after creation. If [target] exists then the type of the link will +/// match the type [target], otherwise a file symlink is created. +/// +/// In order to create a symbolic link on Windows, Dart must be run in +/// Administrator mode or the system must have Developer Mode enabled, +/// otherwise a [FileSystemException] will be raised with +/// `ERROR_PRIVILEGE_NOT_HELD` set as the errno when this call is made. +/// +/// On other platforms, the POSIX symlink() call is used to make a symbolic link +/// containing the string target. If target is a relative path, it will be +/// interpreted relative to the directory containing the link. +/// +/// @description Checks that relative paths to the target will be interpreted +/// relative to the directory containing the link. Test relative path a not +/// existing entity +/// @author sgrekhov22@gmail.com + +import "dart:io"; +import "../../../Utils/expect.dart"; +import "../file_utils.dart"; + +main() { + inSandbox(_main); +} + +_main(Directory sandbox) { + String target = "target"; + Link link = Link(sandbox.path + + Platform.pathSeparator + + getTempFileName(extension: "lnk")); + link.createSync(target); + Expect.equals(target, link.targetSync()); + if (Platform.isWindows) { + Expect.equals( + FileSystemEntityType.link, FileSystemEntity.typeSync(link.path)); + } else { + Expect.equals( + FileSystemEntityType.notFound, FileSystemEntity.typeSync(link.path)); + } + // Now create a directory and into it another directory with the name as + // link's target. Then move the link into the first directory. Its relative + // target should point to the second directory after it + Directory dir1 = getTempDirectorySync(parent: sandbox); + Directory dir2 = Directory(dir1.path + Platform.pathSeparator + target); + dir2.createSync(); + Link moved = + link.renameSync(dir1.path + Platform.pathSeparator + "moved.lnk"); + Expect.equals(target, moved.targetSync()); + if (Platform.isWindows) { + Expect.equals( + FileSystemEntityType.link, FileSystemEntity.typeSync(moved.path)); + } else { + Expect.equals( + FileSystemEntityType.directory, FileSystemEntity.typeSync(moved.path)); + } +} diff --git a/LibTest/io/Link/create_A04_t05.dart b/LibTest/io/Link/create_A04_t05.dart index 6101eadd4f..f08a7ad756 100644 --- a/LibTest/io/Link/create_A04_t05.dart +++ b/LibTest/io/Link/create_A04_t05.dart @@ -57,6 +57,10 @@ _main(Directory sandbox) async { if (Platform.isWindows) { Expect.equals( FileSystemEntityType.link, FileSystemEntity.typeSync(created.path)); + File file = File(created.targetSync()); + file.createSync(); + Expect.equals( + FileSystemEntityType.file, FileSystemEntity.typeSync(created.path)); } else { Expect.equals(FileSystemEntityType.notFound, FileSystemEntity.typeSync(created.path)); diff --git a/LibTest/io/Link/create_A04_t06.dart b/LibTest/io/Link/create_A04_t06.dart index 1887a8f18c..563328df6b 100644 --- a/LibTest/io/Link/create_A04_t06.dart +++ b/LibTest/io/Link/create_A04_t06.dart @@ -54,6 +54,10 @@ _main(Directory sandbox) async { if (Platform.isWindows) { Expect.equals( FileSystemEntityType.link, FileSystemEntity.typeSync(created.path)); + File file = File(created.targetSync()); + file.createSync(); + Expect.equals( + FileSystemEntityType.file, FileSystemEntity.typeSync(created.path)); } else { Expect.equals(FileSystemEntityType.notFound, FileSystemEntity.typeSync(created.path)); diff --git a/LibTest/io/Link/create_A06_t05.dart b/LibTest/io/Link/create_A06_t05.dart index a07e6ea24e..8efa79963b 100644 --- a/LibTest/io/Link/create_A06_t05.dart +++ b/LibTest/io/Link/create_A06_t05.dart @@ -51,8 +51,7 @@ main() async { _main(Directory sandbox) async { String notExisting = getTempFileName(); String target = getTempFileName(extension: "lnk"); - Link targetLink = - getTempLinkSync(parent: sandbox, target: notExisting, name: target); + getTempLinkSync(parent: sandbox, target: notExisting, name: target); Link link = Link(sandbox.path + Platform.pathSeparator + getTempFileName(extension: "lnk"));