@@ -364,26 +364,11 @@ public void testMoveFile() throws IOException {
364
364
365
365
@ Test
366
366
public void testMoveFileAcrossDevices () throws Exception {
367
- class MultipleDeviceFS extends InMemoryFileSystem {
368
- MultipleDeviceFS () {
369
- super (DigestHashFunction .SHA256 );
370
- }
371
-
372
- @ Override
373
- public void renameTo (Path source , Path target ) throws IOException {
374
- if (!source .startsWith (target .asFragment ().subFragment (0 , 1 ))) {
375
- throw new IOException ("EXDEV" );
376
- }
377
- super .renameTo (source , target );
378
- }
379
- }
380
367
FileSystem fs = new MultipleDeviceFS ();
381
- Path dev1 = fs .getPath ("/fs1" );
382
- dev1 .createDirectory ();
383
- Path dev2 = fs .getPath ("/fs2" );
384
- dev2 .createDirectory ();
385
- Path source = dev1 .getChild ("source" );
386
- Path target = dev2 .getChild ("target" );
368
+ Path source = fs .getPath ("/fs1/source" );
369
+ source .getParentDirectory ().createDirectoryAndParents ();
370
+ Path target = fs .getPath ("/fs2/target" );
371
+ target .getParentDirectory ().createDirectoryAndParents ();
387
372
388
373
FileSystemUtils .writeContent (source , UTF_8 , "hello, world" );
389
374
source .setLastModifiedTime (142 );
@@ -394,12 +379,34 @@ public void renameTo(Path source, Path target) throws IOException {
394
379
assertThat (target .getLastModifiedTime ()).isEqualTo (142 );
395
380
396
381
source .createSymbolicLink (PathFragment .create ("link-target" ));
382
+
397
383
assertThat (FileSystemUtils .moveFile (source , target )).isEqualTo (MoveResult .FILE_COPIED );
384
+
398
385
assertThat (source .exists (Symlinks .NOFOLLOW )).isFalse ();
399
386
assertThat (target .isSymbolicLink ()).isTrue ();
400
387
assertThat (target .readSymbolicLink ()).isEqualTo (PathFragment .create ("link-target" ));
401
388
}
402
389
390
+ @ Test
391
+ public void testMoveFileFixPermissions () throws Exception {
392
+ FileSystem fs = new MultipleDeviceFS ();
393
+ Path source = fs .getPath ("/fs1/source" );
394
+ source .getParentDirectory ().createDirectoryAndParents ();
395
+ Path target = fs .getPath ("/fs2/target" );
396
+ target .getParentDirectory ().createDirectoryAndParents ();
397
+
398
+ FileSystemUtils .writeContent (source , UTF_8 , "linear-a" );
399
+ source .setLastModifiedTime (142 );
400
+ source .setReadable (false );
401
+
402
+ MoveResult moveResult = moveFile (source , target );
403
+
404
+ assertThat (moveResult ).isEqualTo (MoveResult .FILE_COPIED );
405
+ assertThat (source .exists (Symlinks .NOFOLLOW )).isFalse ();
406
+ assertThat (target .isFile (Symlinks .NOFOLLOW )).isTrue ();
407
+ assertThat (FileSystemUtils .readContent (target , UTF_8 )).isEqualTo ("linear-a" );
408
+ }
409
+
403
410
@ Test
404
411
public void testReadContentWithLimit () throws IOException {
405
412
createTestDirectoryTree ();
@@ -834,4 +841,18 @@ public void testCreateHardLinkForNonEmptyDirectory_success() throws Exception {
834
841
assertThat (fileSystem .stat (linkPath3 , false ).getNodeId ())
835
842
.isEqualTo (fileSystem .stat (originalPath3 , false ).getNodeId ());
836
843
}
844
+
845
+ static class MultipleDeviceFS extends InMemoryFileSystem {
846
+ MultipleDeviceFS () {
847
+ super (DigestHashFunction .SHA256 );
848
+ }
849
+
850
+ @ Override
851
+ public void renameTo (Path source , Path target ) throws IOException {
852
+ if (!source .startsWith (target .asFragment ().subFragment (0 , 1 ))) {
853
+ throw new IOException ("EXDEV" );
854
+ }
855
+ super .renameTo (source , target );
856
+ }
857
+ }
837
858
}
0 commit comments