Changeset 102195 in vbox
- Timestamp:
- Nov 21, 2023 12:43:15 PM (12 months ago)
- Location:
- trunk/src/libs/xpcom18a4/xpcom/io
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/libs/xpcom18a4/xpcom/io/nsILocalFile.idl
r101944 r102195 42 42 43 43 %{C++ 44 #include "prio.h"45 #include <stdio.h>46 47 44 #include <iprt/ldr.h> 48 45 %} 49 46 50 [ptr] native PRFileDescStar(PRFileDesc);51 47 [ptr] native RTLDRMOD(RTLDRMODINTERNAL); 52 48 [ptr] native FILE(FILE); … … 102 98 */ 103 99 attribute PRBool followLinks; 104 105 [noscript] PRFileDescStar openNSPRFileDesc(in long flags, in long mode);106 [noscript] FILE openANSIFileDesc(in string mode);107 100 108 101 [noscript] RTLDRMOD load(); -
trunk/src/libs/xpcom18a4/xpcom/io/nsLocalFile.h
r101804 r102195 66 66 // on this. 67 67 68 #include <iprt/err.h> 69 68 70 #include <errno.h> 71 69 72 #include "nsILocalFile.h" 70 73 … … 77 80 #endif 78 81 79 #define NSRESULT_FOR_RETURN(ret) (((ret) < 0) ? NSRESULT_FOR_ERRNO() : NS_OK) 82 83 #define NSRESULT_FOR_IPRT(ret) (RT_FAILURE((ret)) ? nsresultForIprt(ret) : NS_OK) 80 84 81 85 inline nsresult 82 nsresultFor Errno(int err)86 nsresultForIprt(int err) 83 87 { 84 88 switch (err) { 85 case 0:89 case VINF_SUCCESS: 86 90 return NS_OK; 87 case ENOENT: 91 case VERR_NOT_FOUND: 92 case VERR_FILE_NOT_FOUND: 93 case VERR_PATH_NOT_FOUND: 88 94 return NS_ERROR_FILE_TARGET_DOES_NOT_EXIST; 89 case ENOTDIR:95 case VERR_NOT_A_DIRECTORY: 90 96 return NS_ERROR_FILE_DESTINATION_NOT_DIR; 91 #ifdef ENOLINK 92 case ENOLINK: 97 case VERR_NOT_SYMLINK: 93 98 return NS_ERROR_FILE_UNRESOLVABLE_SYMLINK; 94 #endif /* ENOLINK */ 95 case EEXIST: 99 case VERR_ALREADY_EXISTS: 96 100 return NS_ERROR_FILE_ALREADY_EXISTS; 97 #ifdef EPERM 98 case EPERM: 99 #endif /* EPERM */ 100 case EACCES: 101 case VERR_ACCESS_DENIED: 101 102 return NS_ERROR_FILE_ACCESS_DENIED; 102 103 default: … … 105 106 } 106 107 107 #define NSRESULT_FOR_ERRNO() nsresultFor Errno(errno)108 #define NSRESULT_FOR_ERRNO() nsresultForIprt(RTErrConvertFromErrno(errno)) 108 109 109 110 void NS_StartupLocalFile(); -
trunk/src/libs/xpcom18a4/xpcom/io/nsLocalFileUnix.cpp
r102050 r102195 76 76 #include "prerr.h" 77 77 78 #include <iprt/errcore.h> 78 #include <iprt/err.h> 79 #include <iprt/dir.h> 80 #include <iprt/file.h> 81 #include <iprt/path.h> 82 #include <iprt/time.h> 79 83 80 84 #define FILE_STRCMP strcmp … … 97 101 98 102 NS_COM nsresult 99 NS_ErrorAccordingToNSPR() 100 { 101 PRErrorCode err = PR_GetError(); 102 switch (err) { 103 case PR_OUT_OF_MEMORY_ERROR: return NS_ERROR_OUT_OF_MEMORY; 104 case PR_WOULD_BLOCK_ERROR: return NS_BASE_STREAM_WOULD_BLOCK; 105 case PR_FILE_NOT_FOUND_ERROR: return NS_ERROR_FILE_NOT_FOUND; 106 case PR_READ_ONLY_FILESYSTEM_ERROR: return NS_ERROR_FILE_READ_ONLY; 107 case PR_NOT_DIRECTORY_ERROR: return NS_ERROR_FILE_NOT_DIRECTORY; 108 case PR_IS_DIRECTORY_ERROR: return NS_ERROR_FILE_IS_DIRECTORY; 109 case PR_LOOP_ERROR: return NS_ERROR_FILE_UNRESOLVABLE_SYMLINK; 110 case PR_FILE_EXISTS_ERROR: return NS_ERROR_FILE_ALREADY_EXISTS; 111 case PR_FILE_IS_LOCKED_ERROR: return NS_ERROR_FILE_IS_LOCKED; 112 case PR_FILE_TOO_BIG_ERROR: return NS_ERROR_FILE_TOO_BIG; 113 case PR_NO_DEVICE_SPACE_ERROR: return NS_ERROR_FILE_NO_DEVICE_SPACE; 114 case PR_NAME_TOO_LONG_ERROR: return NS_ERROR_FILE_NAME_TOO_LONG; 115 case PR_DIRECTORY_NOT_EMPTY_ERROR: return NS_ERROR_FILE_DIR_NOT_EMPTY; 116 case PR_NO_ACCESS_RIGHTS_ERROR: return NS_ERROR_FILE_ACCESS_DENIED; 103 NS_ErrorAccordingToIPRT(int vrc) 104 { 105 switch (vrc) { 106 case VERR_NO_MEMORY: return NS_ERROR_OUT_OF_MEMORY; 107 case VERR_FILE_NOT_FOUND: return NS_ERROR_FILE_NOT_FOUND; 108 case VERR_PATH_NOT_FOUND: return NS_ERROR_FILE_NOT_FOUND; 109 case VERR_NOT_A_DIRECTORY: return NS_ERROR_FILE_NOT_DIRECTORY; 110 case VERR_IS_A_DIRECTORY: return NS_ERROR_FILE_IS_DIRECTORY; 111 case VERR_ALREADY_EXISTS: return NS_ERROR_FILE_ALREADY_EXISTS; 112 case VERR_FILE_LOCK_VIOLATION: return NS_ERROR_FILE_IS_LOCKED; 113 case VERR_FILE_TOO_BIG: return NS_ERROR_FILE_TOO_BIG; 114 case VERR_FILENAME_TOO_LONG: return NS_ERROR_FILE_NAME_TOO_LONG; 115 case VERR_DIR_NOT_EMPTY: return NS_ERROR_FILE_DIR_NOT_EMPTY; 116 case VERR_ACCESS_DENIED: return NS_ERROR_FILE_ACCESS_DENIED; 117 case VERR_WRITE_PROTECT: return NS_ERROR_FILE_READ_ONLY; 118 case VERR_DISK_FULL: return NS_ERROR_FILE_NO_DEVICE_SPACE; 119 120 /** @todo: No IPRT equivalent right now (but shouldn't be important). */ 121 //case PR_WOULD_BLOCK_ERROR: return NS_BASE_STREAM_WOULD_BLOCK; 117 122 default: return NS_ERROR_FAILURE; 118 123 } … … 370 375 */ 371 376 if (mkdir_result == -1 && mkdir_errno != EEXIST) 372 return nsresultFor Errno(mkdir_errno);377 return nsresultForIprt(RTErrConvertFromErrno(mkdir_errno)); 373 378 } 374 379 … … 380 385 } 381 386 382 NS_IMETHODIMP383 nsLocalFile::OpenNSPRFileDesc(PRInt32 flags, PRInt32 mode, PRFileDesc **_retval)384 {385 *_retval = PR_Open(mPath.get(), flags, mode);386 if (! *_retval)387 return NS_ErrorAccordingToNSPR();388 389 return NS_OK;390 }391 392 NS_IMETHODIMP393 nsLocalFile::OpenANSIFileDesc(const char *mode, FILE **_retval)394 {395 *_retval = fopen(mPath.get(), mode);396 if (! *_retval)397 return NS_ERROR_FAILURE;398 399 return NS_OK;400 }401 402 387 static int 403 do_create(const char *path, PRIntn flags, mode_t mode, PRFileDesc **_retval) 404 { 405 *_retval = PR_Open(path, flags, mode); 406 return *_retval ? 0 : -1; 388 do_create(const char *path, uint32_t flags, mode_t mode, RTFILE *_retval) 389 { 390 return RTFileOpen(_retval, path, flags | (mode << RTFILE_O_CREATE_MODE_SHIFT)); 407 391 } 408 392 409 393 static int 410 do_mkdir(const char *path, PRIntn flags, mode_t mode, PRFileDesc **_retval)411 { 412 *_retval = nsnull;413 return mkdir(path, mode);394 do_mkdir(const char *path, uint32_t flags, mode_t mode, RTFILE *_retval) 395 { 396 *_retval = NULL; 397 return RTDirCreate(path, mode, 0 /* fCreate*/); 414 398 } 415 399 416 400 nsresult 417 nsLocalFile::CreateAndKeepOpen(PRUint32 type, PRIntnflags,418 PRUint32 permissions, PRFileDesc **_retval)401 nsLocalFile::CreateAndKeepOpen(PRUint32 type, uint32_t flags, 402 PRUint32 permissions, RTFILE *_retval) 419 403 { 420 404 if (type != NORMAL_FILE_TYPE && type != DIRECTORY_TYPE) 421 405 return NS_ERROR_FILE_UNKNOWN_TYPE; 422 406 423 int result; 424 int (*createFunc)(const char *, PRIntn, mode_t, PRFileDesc **) = 407 int (*createFunc)(const char *, uint32_t, mode_t, RTFILE *) = 425 408 (type == NORMAL_FILE_TYPE) ? do_create : do_mkdir; 426 409 427 result= createFunc(mPath.get(), flags, permissions, _retval);428 if ( result == -1 && errno == ENOENT) {410 int vrc = createFunc(mPath.get(), flags, permissions, _retval); 411 if (vrc == VERR_PATH_NOT_FOUND || vrc == VERR_FILE_NOT_FOUND || vrc == VERR_NOT_FOUND) { 429 412 /* 430 413 * If we failed because of missing ancestor components, try to create … … 455 438 fprintf(stderr, "nsIFile: Create(\"%s\") again\n", mPath.get()); 456 439 #endif 457 result= createFunc(mPath.get(), flags, permissions, _retval);458 } 459 460 return NSRESULT_FOR_ RETURN(result);440 vrc = createFunc(mPath.get(), flags, permissions, _retval); 441 } 442 443 return NSRESULT_FOR_IPRT(vrc); 461 444 } 462 445 … … 464 447 nsLocalFile::Create(PRUint32 type, PRUint32 permissions) 465 448 { 466 PRFileDesc *junk = nsnull;449 RTFILE junk = NULL; 467 450 nsresult rv = CreateAndKeepOpen(type, 468 PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE |469 PR_EXCL,451 RTFILE_O_WRITE | RTFILE_O_CREATE | RTFILE_O_TRUNCATE | 452 RTFILE_O_DENY_ALL, 470 453 permissions, 471 454 &junk); 472 455 if (junk) 473 PR_Close(junk);456 RTFileClose(junk); 474 457 return rv; 475 458 } … … 793 776 // open it successfully for writing. 794 777 795 PRFileDesc *newFD;778 RTFILE newFD; 796 779 rv = newFile->CreateAndKeepOpen(NORMAL_FILE_TYPE, 797 PR_WRONLY|PR_CREATE_FILE|PR_TRUNCATE,780 RTFILE_O_WRITE | RTFILE_O_CREATE | RTFILE_O_TRUNCATE | RTFILE_O_DENY_NONE, 798 781 myPerms, 799 782 &newFD); … … 804 787 PRBool specialFile; 805 788 if (NS_FAILED(rv = IsSpecial(&specialFile))) { 806 PR_Close(newFD);789 RTFileClose(newFD); 807 790 return rv; 808 791 } … … 812 795 #endif 813 796 // make sure to clean up properly 814 PR_Close(newFD);797 RTFileClose(newFD); 815 798 return NS_OK; 816 799 } 817 800 818 PRFileDesc *oldFD; 819 rv = OpenNSPRFileDesc(PR_RDONLY, myPerms, &oldFD); 801 RTFILE oldFD = NIL_RTFILE; 802 int vrc = RTFileOpen(&oldFD, mPath.get(), RTFILE_O_OPEN | RTFILE_O_READ | RTFILE_O_DENY_NONE); 803 if (RT_FAILURE(vrc)) 804 rv = NS_ErrorAccordingToIPRT(vrc); 820 805 if (NS_FAILED(rv)) { 821 806 // make sure to clean up properly 822 PR_Close(newFD);807 RTFileClose(newFD); 823 808 return rv; 824 809 } 825 810 826 #ifdef DEBUG_blizzard 827 PRInt32 totalRead = 0; 828 PRInt32 totalWritten = 0; 829 #endif 830 char buf[BUFSIZ]; 831 PRInt32 bytesRead; 832 833 while ((bytesRead = PR_Read(oldFD, buf, BUFSIZ)) > 0) { 834 #ifdef DEBUG_blizzard 835 totalRead += bytesRead; 836 #endif 837 838 // PR_Write promises never to do a short write 839 PRInt32 bytesWritten = PR_Write(newFD, buf, bytesRead); 840 if (bytesWritten < 0) { 841 bytesRead = -1; 842 break; 843 } 844 NS_ASSERTION(bytesWritten == bytesRead, "short PR_Write?"); 845 846 #ifdef DEBUG_blizzard 847 totalWritten += bytesWritten; 848 #endif 849 } 850 851 #ifdef DEBUG_blizzard 852 printf("read %d bytes, wrote %d bytes\n", 853 totalRead, totalWritten); 854 #endif 811 vrc = RTFileCopyByHandles(oldFD, newFD); 855 812 856 813 // close the files 857 PR_Close(newFD);858 PR_Close(oldFD);814 RTFileClose(newFD); 815 RTFileClose(oldFD); 859 816 860 817 // check for read (or write) error after cleaning up 861 if ( bytesRead < 0)818 if (RT_FAILURE(vrc)) 862 819 return NS_ERROR_OUT_OF_MEMORY; 863 820 } … … 915 872 916 873 if (!recursive && isSymLink) 917 return NSRESULT_FOR_ RETURN(unlink(mPath.get()));874 return NSRESULT_FOR_IPRT(RTErrConvertFromErrno(unlink(mPath.get()))); 918 875 919 876 isDir = S_ISDIR(mCachedStat.st_mode); … … 962 919 NS_ENSURE_ARG(aLastModTime); 963 920 964 PRFileInfo64info;965 i f (PR_GetFileInfo64(mPath.get(), &info) != PR_SUCCESS)966 return NSRESULT_FOR_ERRNO();967 968 // PRTime is a 64 bit value 921 RTFSOBJINFO info; 922 int vrc = RTPathQueryInfo(mPath.get(), &info, RTFSOBJATTRADD_NOTHING); 923 if (RT_FAILURE(vrc)) 924 return NSRESULT_FOR_IPRT(vrc); 925 969 926 // microseconds -> milliseconds 970 PRInt64 usecPerMsec; 971 LL_I2L(usecPerMsec, PR_USEC_PER_MSEC); 972 LL_DIV(*aLastModTime, info.modifyTime, usecPerMsec); 927 *aLastModTime = RTTimeSpecGetMilli(&info.ModificationTime); 973 928 return NS_OK; 974 929 } … … 994 949 } 995 950 InvalidateCache(); 996 return NSRESULT_FOR_ RETURN(result);951 return NSRESULT_FOR_IPRT(RTErrConvertFromErrno(result)); 997 952 } 998 953 -
trunk/src/libs/xpcom18a4/xpcom/io/nsLocalFileUnix.h
r1 r102195 44 44 #ifndef _nsLocalFileUNIX_H_ 45 45 #define _nsLocalFileUNIX_H_ 46 47 #include <iprt/file.h> 46 48 47 49 #include <sys/stat.h> … … 126 128 nsresult FillStatCache(); 127 129 128 nsresult CreateAndKeepOpen(PRUint32 type, PRIntnflags,129 PRUint32 permissions, PRFileDesc **_retval);130 nsresult CreateAndKeepOpen(PRUint32 type, uint32_t flags, 131 PRUint32 permissions, RTFILE *_retval); 130 132 }; 131 133
Note:
See TracChangeset
for help on using the changeset viewer.