1616#include " mozilla/Unused.h"
1717#include " nsAppDirectoryServiceDefs.h"
1818#include " nsDirectoryServiceUtils.h"
19+ #include " nsLocalFile.h"
1920#include " nsPrintfCString.h"
2021#include " mozilla/StackWalk.h"
2122#include " plstr.h"
2223#include " prio.h"
2324
2425#ifdef XP_WIN
25- #define NS_T (str ) L ## str
2626#define NS_SLASH " \\ "
2727#include < fcntl.h>
2828#include < io.h>
@@ -92,21 +92,22 @@ RecordStackWalker(uint32_t aFrameNumber, void* aPC, void* aSP, void* aClosure)
9292 */
9393class LateWriteObserver final : public IOInterposeObserver
9494{
95+ using char_type = filesystem::Path::value_type;
9596public:
96- explicit LateWriteObserver (const char * aProfileDirectory)
97- : mProfileDirectory(PL_strdup (aProfileDirectory))
97+ explicit LateWriteObserver (const char_type * aProfileDirectory)
98+ : mProfileDirectory(NS_strdup (aProfileDirectory))
9899 {
99100 }
100101 ~LateWriteObserver ()
101102 {
102- PL_strfree (mProfileDirectory );
103+ free (mProfileDirectory );
103104 mProfileDirectory = nullptr ;
104105 }
105106
106107 void Observe (IOInterposeObserver::Observation& aObservation) override ;
107108
108109private:
109- char * mProfileDirectory ;
110+ char_type * mProfileDirectory ;
110111};
111112
112113void
@@ -130,9 +131,9 @@ LateWriteObserver::Observe(IOInterposeObserver::Observation& aOb)
130131 &rawStack);
131132 Telemetry::ProcessedStack stack = Telemetry::GetStackAndModules (rawStack);
132133
133- nsPrintfCString nameAux (" %s%s%s " , mProfileDirectory ,
134- NS_SLASH , " Telemetry.LateWriteTmpXXXXXX" );
135- char * name;
134+ nsTAutoString<char_type> nameAux (mProfileDirectory );
135+ nameAux. AppendLiteral ( NS_SLASH " Telemetry.LateWriteTmpXXXXXX" );
136+ char_type * name;
136137 nameAux.GetMutableData (&name);
137138
138139 // We want the sha1 of the entire file, so please don't write to fd
@@ -142,9 +143,9 @@ LateWriteObserver::Observe(IOInterposeObserver::Observation& aOb)
142143 HANDLE hFile;
143144 do {
144145 // mkstemp isn't supported so keep trying until we get a file
145- _mktemp_s ( name, strlen (name) + 1 );
146- hFile = CreateFileA ( name, GENERIC_WRITE , 0 , nullptr , CREATE_NEW ,
147- FILE_ATTRIBUTE_NORMAL , nullptr );
146+ _wmktemp_s ( char16ptr_t ( name), NS_strlen (name) + 1 );
147+ hFile = CreateFileW ( char16ptr_t ( name) , GENERIC_WRITE , 0 , nullptr ,
148+ CREATE_NEW , FILE_ATTRIBUTE_NORMAL , nullptr );
148149 } while (GetLastError () == ERROR_FILE_EXISTS );
149150
150151 if (hFile == INVALID_HANDLE_VALUE ) {
@@ -202,13 +203,12 @@ LateWriteObserver::Observe(IOInterposeObserver::Observation& aOb)
202203
203204 // We append the sha1 of the contents to the file name. This provides a simple
204205 // client side deduplication.
205- nsPrintfCString finalName (" %s%s" , mProfileDirectory ,
206- " /Telemetry.LateWriteFinal-" );
206+ nsAutoString finalName (NS_LITERAL_STRING (" Telemetry.LateWriteFinal-" ));
207207 for (int i = 0 ; i < 20 ; ++i) {
208208 finalName.AppendPrintf (" %02x" , sha1[i]);
209209 }
210- PR_Delete (finalName. get () );
211- PR_Rename (name , finalName. get () );
210+ RefPtr<nsLocalFile> file = new nsLocalFile (nameAux );
211+ file-> RenameTo ( nullptr , finalName);
212212}
213213
214214/* ****************************** Setup/Teardown *******************************/
@@ -223,9 +223,8 @@ InitLateWriteChecks()
223223 nsCOMPtr<nsIFile> mozFile;
224224 NS_GetSpecialDirectory (NS_APP_USER_PROFILE_50_DIR , getter_AddRefs(mozFile));
225225 if (mozFile) {
226- nsAutoCString nativePath;
227- nsresult rv = mozFile->GetNativePath (nativePath);
228- if (NS_SUCCEEDED (rv) && nativePath.get ()) {
226+ PathString nativePath = mozFile->NativePath ();
227+ if (nativePath.get ()) {
229228 sLateWriteObserver = new LateWriteObserver (nativePath.get ());
230229 }
231230 }
0 commit comments