@@ -60,7 +60,7 @@ public OneDriveUploader(UploadLogger logger) {
6060 this .logger = logger ;
6161 setAuthProvider (AuthenticationProvider .ONEDRIVE );
6262 try {
63- refreshToken = Authenticator .getRefreshToken (AuthenticationProvider . ONEDRIVE );
63+ refreshToken = Authenticator .getRefreshToken (getAuthProvider () );
6464 retrieveNewAccessToken ();
6565 } catch (Exception e ) {
6666 MessageUtil .sendConsoleException (e );
@@ -76,7 +76,7 @@ public OneDriveUploader(UploadLogger logger) {
7676 */
7777 private void retrieveNewAccessToken () throws Exception {
7878 RequestBody requestBody = new FormBody .Builder ()
79- .add ("client_id" , Obfusticate .decrypt (AuthenticationProvider . ONEDRIVE .getClientId ()))
79+ .add ("client_id" , Obfusticate .decrypt (getAuthProvider () .getClientId ()))
8080 .add ("scope" , "offline_access Files.ReadWrite" )
8181 .add ("refresh_token" , refreshToken )
8282 .add ("grant_type" , "refresh_token" )
@@ -94,6 +94,7 @@ private void retrieveNewAccessToken() throws Exception {
9494 throw new IOException (String .format ("%s : %s" , error , description ));
9595 }
9696 accessToken = parsedResponse .getString ("access_token" );
97+ refreshToken = parsedResponse .getString ("refresh_token" );
9798 }
9899 }
99100
@@ -129,31 +130,40 @@ public void test(File testFile) {
129130 @ Override
130131 public void uploadFile (File file , String location ) {
131132 try {
133+ retrieveNewAccessToken ();
132134 String destinationRoot = normalizePath (ConfigParser .getConfig ().backupStorage .remoteDirectory );
133135 String destinationPath = concatPath (destinationRoot , normalizePath (location ));
134136 FQID destinationId = createPath (destinationPath );
135137 String uploadURL = createUploadSession (file .getName (), destinationId );
136138 try (RandomAccessFile raf = new RandomAccessFile (file , "r" )) {
137139 uploadToSession (uploadURL , raf );
138- try {
139- pruneBackups (destinationId );
140- } catch (Exception e ) {
141- logger .log (intl ("backup-method-prune-failed" ));
142- throw e ;
143- }
144140 }
145- } catch (Exception exception ) {
141+ try {
142+ pruneBackups (destinationId );
143+ } catch (Exception e ) {
144+ logger .log (intl ("backup-method-prune-failed" ));
145+ throw e ;
146+ }
147+ }
148+ catch (Exception exception ) {
146149 NetUtil .catchException (exception , "graph.microsoft.com" , logger );
147150 MessageUtil .sendConsoleException (exception );
148151 setErrorOccurred (true );
152+ if (exception instanceof InterruptedException ) {
153+ Thread .currentThread ().interrupt ();
154+ }
149155 }
150156 }
151157
152158 /**
153159 * Closes any remaining connections retrieveNewAccessToken
154160 */
155161 public void close () {
156- // nothing needs to be done
162+ try {
163+ Authenticator .saveRefreshToken (getAuthProvider (), refreshToken );
164+ } catch (Exception e ) {
165+ MessageUtil .sendConsoleException (e );
166+ }
157167 }
158168
159169 /**
0 commit comments