@@ -271,7 +271,15 @@ Nextcloud.prototype = {
271271 createExistingAccount : function nsNc_createExistingAccount ( aRequestObserver ) {
272272 // XXX: replace this with a better function
273273 let successCb = function ( ) {
274- aRequestObserver . onStopRequest ( null , this , Cr . NS_OK ) ;
274+ let folderExists = function ( exists ) {
275+ if ( exists ) {
276+ aRequestObserver . onStopRequest ( null , this , Cr . NS_OK ) ;
277+ }
278+ else {
279+ aRequestObserver . onStopRequest ( null , this , Ci . nsIMsgCloudFileProvider . authErr ) ;
280+ }
281+ } . bind ( this ) ;
282+ this . _checkFolderExists ( folderExists ) ;
275283 } . bind ( this ) ;
276284
277285 let failureCb = function ( ) {
@@ -586,6 +594,45 @@ Nextcloud.prototype = {
586594 return quota && quota . length && Number ( quota [ 0 ] . textContent ) || - 1 ;
587595 } ,
588596
597+ /**
598+ * A private function that checks that the folder entered in the
599+ * settings screen exists on the server.
600+ *
601+ * @param callback callback function called with true or false as an argument
602+ */
603+ _checkFolderExists : function nsOwncloud_checkFolderExists ( callback ) {
604+ if ( this . _storageFolder !== '/' ) {
605+ let body = '<propfind xmlns="DAV:">' +
606+ '<prop>' +
607+ '<resourcetype />' +
608+ '</prop>' +
609+ '</propfind>' ;
610+
611+ let req = Cc [ "@mozilla.org/xmlextras/xmlhttprequest;1" ]
612+ . createInstance ( Ci . nsIXMLHttpRequest ) ;
613+
614+ req . open ( "PROPFIND" , this . _serverUrl + kWebDavPath + ( "/" + this . _storageFolder + "/" ) . replace ( / \/ + / g, '/' ) , true , this . _userName , this . _password ) ;
615+ req . onerror = function ( ) {
616+ this . log . info ( "failure checking folder" ) ;
617+ callback ( false ) ;
618+ } . bind ( this ) ;
619+
620+ req . onload = function ( ) {
621+ if ( req . status === 207 ) {
622+ return callback ( true ) ;
623+ }
624+ else {
625+ return callback ( false ) ;
626+ }
627+ } . bind ( this ) ;
628+
629+ req . send ( body ) ;
630+ }
631+ else {
632+ return callback ( true ) ;
633+ }
634+ } ,
635+
589636 /**
590637 * A private function that first ensures that the user is logged in, and then
591638 * retrieves the user's profile information.
0 commit comments