src/solaris/classes/sun/nio/fs/UnixCopyFile.java

Print this page




 220                                  UnixFileAttributes attrs,
 221                                  UnixPath  target,
 222                                  Flags flags,
 223                                  long addressToPollForCancel)
 224         throws IOException
 225     {
 226         int fi = -1;
 227         try {
 228             fi = open(source, O_RDONLY, 0);
 229         } catch (UnixException x) {
 230             x.rethrowAsIOException(source);
 231         }
 232 
 233         try {
 234             // open new file
 235             int fo = -1;
 236             try {
 237                 fo = open(target,
 238                            (O_WRONLY |
 239                             O_CREAT |
 240                             O_TRUNC),
 241                            attrs.mode());
 242             } catch (UnixException x) {
 243                 x.rethrowAsIOException(target);
 244             }
 245 
 246             // set to true when file and attributes copied
 247             boolean complete = false;
 248             try {
 249                 // transfer bytes to target file
 250                 try {
 251                     transfer(fo, fi, addressToPollForCancel);
 252                 } catch (UnixException x) {
 253                     x.rethrowAsIOException(source, target);
 254                 }
 255                 // copy owner/permissions
 256                 if (flags.copyPosixAttributes) {
 257                     try {
 258                         fchown(fo, attrs.uid(), attrs.gid());
 259                         fchmod(fo, attrs.mode());
 260                     } catch (UnixException x) {


 418         if (targetExists) {
 419             if (sourceAttrs.isSameFile(targetAttrs))
 420                 return;  // nothing to do as files are identical
 421             if (!flags.replaceExisting) {
 422                 throw new FileAlreadyExistsException(
 423                     target.getPathForExecptionMessage());
 424             }
 425 
 426             // attempt to delete target
 427             try {
 428                 if (targetAttrs.isDirectory()) {
 429                     rmdir(target);
 430                 } else {
 431                     unlink(target);
 432                 }
 433             } catch (UnixException x) {
 434                 // target is non-empty directory that can't be replaced.
 435                 if (targetAttrs.isDirectory() &&
 436                    (x.errno() == EEXIST || x.errno() == ENOTEMPTY))
 437                 {
 438                     throw new FileAlreadyExistsException(
 439                         source.getPathForExecptionMessage(),
 440                         target.getPathForExecptionMessage(),
 441                         x.getMessage());
 442                 }
 443                 x.rethrowAsIOException(target);
 444             }
 445         }
 446 
 447         // first try rename
 448         try {
 449             rename(source, target);
 450             return;
 451         } catch (UnixException x) {
 452             if (x.errno() != EXDEV && x.errno() != EISDIR) {
 453                 x.rethrowAsIOException(source, target);
 454             }
 455         }
 456 
 457         // copy source to target
 458         if (sourceAttrs.isDirectory()) {
 459             copyDirectory(source, sourceAttrs, target, flags);
 460         } else {
 461             if (sourceAttrs.isSymbolicLink()) {


 539         // 1. check if source and target are the same file
 540         // 2. throw exception if REPLACE_EXISTING option is not set
 541         // 3. try to unlink the target
 542         if (targetExists) {
 543             if (sourceAttrs.isSameFile(targetAttrs))
 544                 return;  // nothing to do as files are identical
 545             if (!flags.replaceExisting)
 546                 throw new FileAlreadyExistsException(
 547                     target.getPathForExecptionMessage());
 548             try {
 549                 if (targetAttrs.isDirectory()) {
 550                     rmdir(target);
 551                 } else {
 552                     unlink(target);
 553                 }
 554             } catch (UnixException x) {
 555                 // target is non-empty directory that can't be replaced.
 556                 if (targetAttrs.isDirectory() &&
 557                    (x.errno() == EEXIST || x.errno() == ENOTEMPTY))
 558                 {
 559                     throw new FileAlreadyExistsException(
 560                         source.getPathForExecptionMessage(),
 561                         target.getPathForExecptionMessage(),
 562                         x.getMessage());
 563                 }
 564                 x.rethrowAsIOException(target);
 565             }
 566         }
 567 
 568         // do the copy
 569         if (sourceAttrs.isDirectory()) {
 570             copyDirectory(source, sourceAttrs, target, flags);
 571             return;
 572         }
 573         if (sourceAttrs.isSymbolicLink()) {
 574             copyLink(source, sourceAttrs, target, flags);
 575             return;
 576         }
 577         if (!flags.interruptible) {
 578             // non-interruptible file copy
 579             copyFile(source, sourceAttrs, target, flags, 0L);
 580             return;
 581         }
 582 




 220                                  UnixFileAttributes attrs,
 221                                  UnixPath  target,
 222                                  Flags flags,
 223                                  long addressToPollForCancel)
 224         throws IOException
 225     {
 226         int fi = -1;
 227         try {
 228             fi = open(source, O_RDONLY, 0);
 229         } catch (UnixException x) {
 230             x.rethrowAsIOException(source);
 231         }
 232 
 233         try {
 234             // open new file
 235             int fo = -1;
 236             try {
 237                 fo = open(target,
 238                            (O_WRONLY |
 239                             O_CREAT |
 240                             O_EXCL),
 241                            attrs.mode());
 242             } catch (UnixException x) {
 243                 x.rethrowAsIOException(target);
 244             }
 245 
 246             // set to true when file and attributes copied
 247             boolean complete = false;
 248             try {
 249                 // transfer bytes to target file
 250                 try {
 251                     transfer(fo, fi, addressToPollForCancel);
 252                 } catch (UnixException x) {
 253                     x.rethrowAsIOException(source, target);
 254                 }
 255                 // copy owner/permissions
 256                 if (flags.copyPosixAttributes) {
 257                     try {
 258                         fchown(fo, attrs.uid(), attrs.gid());
 259                         fchmod(fo, attrs.mode());
 260                     } catch (UnixException x) {


 418         if (targetExists) {
 419             if (sourceAttrs.isSameFile(targetAttrs))
 420                 return;  // nothing to do as files are identical
 421             if (!flags.replaceExisting) {
 422                 throw new FileAlreadyExistsException(
 423                     target.getPathForExecptionMessage());
 424             }
 425 
 426             // attempt to delete target
 427             try {
 428                 if (targetAttrs.isDirectory()) {
 429                     rmdir(target);
 430                 } else {
 431                     unlink(target);
 432                 }
 433             } catch (UnixException x) {
 434                 // target is non-empty directory that can't be replaced.
 435                 if (targetAttrs.isDirectory() &&
 436                    (x.errno() == EEXIST || x.errno() == ENOTEMPTY))
 437                 {
 438                     throw new DirectoryNotEmptyException(
 439                         target.getPathForExecptionMessage());


 440                 }
 441                 x.rethrowAsIOException(target);
 442             }
 443         }
 444 
 445         // first try rename
 446         try {
 447             rename(source, target);
 448             return;
 449         } catch (UnixException x) {
 450             if (x.errno() != EXDEV && x.errno() != EISDIR) {
 451                 x.rethrowAsIOException(source, target);
 452             }
 453         }
 454 
 455         // copy source to target
 456         if (sourceAttrs.isDirectory()) {
 457             copyDirectory(source, sourceAttrs, target, flags);
 458         } else {
 459             if (sourceAttrs.isSymbolicLink()) {


 537         // 1. check if source and target are the same file
 538         // 2. throw exception if REPLACE_EXISTING option is not set
 539         // 3. try to unlink the target
 540         if (targetExists) {
 541             if (sourceAttrs.isSameFile(targetAttrs))
 542                 return;  // nothing to do as files are identical
 543             if (!flags.replaceExisting)
 544                 throw new FileAlreadyExistsException(
 545                     target.getPathForExecptionMessage());
 546             try {
 547                 if (targetAttrs.isDirectory()) {
 548                     rmdir(target);
 549                 } else {
 550                     unlink(target);
 551                 }
 552             } catch (UnixException x) {
 553                 // target is non-empty directory that can't be replaced.
 554                 if (targetAttrs.isDirectory() &&
 555                    (x.errno() == EEXIST || x.errno() == ENOTEMPTY))
 556                 {
 557                     throw new DirectoryNotEmptyException(
 558                         target.getPathForExecptionMessage());


 559                 }
 560                 x.rethrowAsIOException(target);
 561             }
 562         }
 563 
 564         // do the copy
 565         if (sourceAttrs.isDirectory()) {
 566             copyDirectory(source, sourceAttrs, target, flags);
 567             return;
 568         }
 569         if (sourceAttrs.isSymbolicLink()) {
 570             copyLink(source, sourceAttrs, target, flags);
 571             return;
 572         }
 573         if (!flags.interruptible) {
 574             // non-interruptible file copy
 575             copyFile(source, sourceAttrs, target, flags, 0L);
 576             return;
 577         }
 578