Sublime Text 3出現無法保存文件的奇怪現象及幾種解決方法

Sublime Text 是最近用得比較多的編輯器,也是很流行的工具之一。上手之后碼字效率高了很多。

最近本本升級到Win10后,把之前win7的Sublime Text目錄直接拷到win10,簡單配置了一下就可以正常用了。本以一切如常,突然某天發現把一個文件另存成一個新的文件的時候 每一次都提示類似這么一對話框:

Unable to save
D:\xampp\htdocs\websites\dev.liverpool\style\main.scss
Error:
MoveFileEx(D:\xampp\htdocs\websites\dev.liverpool\style\.sublae1.tmp, D:\xampp\htdocs\websites\dev.liverpoolzstylezmain.scss) failed,
Access is denied.

前幾次以為是個別現象沒去管它,后來一起出現受不了。

內事不決問百度,無果。Bing也無果,只好翻出去問GG了。

在一個論壇找到了幾個解決辦法,先和大家分享一下,但最終我個人的解決方法卻是個詭異的現象。

先說國外網友的幾個方法,原帖:http://stackoverflow.com/questions/18264507/sublime-text-unable-to-save

一、讓Sublime Text 以管理員身份運行(這招對我無效)

1. Go to the path where you installed sublime text 2 and...
2. Right click on the sublime_text 2.exe file.
3. Go to its properties.
4. Go to compatibility section under this.
5. Set its privilege level to "Run this program as an administrator".
6. Now change settings for all users and there also check the field "Run this program as an administrator".
7. Apply the changes.

大概意思就是:
右擊Sublime Text -> 屬性 -> 兼容性 -> 選中以管理員身份運行 -> 更改所有用戶設置 -> 以管理員身份運行,確定保存

我測試了一下,操作后每次運行 Sublime Text 都會有Windons 安全風險提示。這不重要,重要的是問題沒有解決,還是會出現之前的問題。但論壇上有人反應他通過這種方式解決了問題。


二、認為是權限問題,給Sublime加所有權限(對我也不效,且我覺得這個思路也不對)

I just solved the same issue on Sublime Text 3 beta, Stable Channel Build 3065 by doing the following under Windows 7:

1. Navigate to the Sublime Text 3 executable file, wherever you have it installed.
2.Right-click it and select properties.
3.Click on the tab marked "Security"
4.About half way down the tab, on the right hand side, under the list of group and user names is this little button:Click it.

5. If your machine is setup the way I suspect it is (otherwise you probably would not be having this issue), you should be prompted for your administrator account credentials. Enter them.Now, select the Users group in the list, then take a look in the box at the bottom labeled 'Permissions for Users'. Put a check mark in the 'Allow' column for the 'Write' item.



6. Click 'Apply'
7. Click 'OK'
You should be set. What this does is it essentially gives Sublime the ability to write files while running with regular user privileges, no administrator level access required. Upon taking a better look at your error, what is happening is Sublime Text is creating a temp file for editing, rather than editing to file itself, then attempting to overwrite the original file with the temp on save. The problem is that the program is not being run by a user with sufficient privileges to perform the overwrite, hence the failure with an 'Access denied' message.

大概意思就是讓sulime text.exe給users用戶組加上所有權限。我試了無效,還把所有的用戶都加了所有權限,也無效。
我覺得這個方法的思路可能不對,于是我把目光轉向了保存目錄的權限,加了everyone的所有權限都加上。依然不行。


三、關閉Sublime Text的atomic_save(這招有效,但我卻不希望關掉)

1、打開Sublime Text
2、首選項 -> 設置-用戶
3、配置中加一行:"atomic_save": false,
4、保存,再試問題解決了。

到此,問題好像解決了。

  但是,心下很不爽,不知道這是什么意思,感覺是把自動保存給關閉了?為什么關閉了這個就可以了?按提示是說SublimeText是在把.tmp文件移過成目標文件的時候出錯了,猜是目標文件可能被占用或者鎖定了。于是我試了一下在其它目錄下進行類似的操作,發現其它目錄下竟然沒問題。好像越來越接近真相了。仔細思索兩目錄的不同,感覺可能和我用了群暉的同步功能有關(是的,你沒看錯,我辜負了你們,快盤倒后,自稱“不會停服”的360也打臉了。我只能忍痛轉用了群暉。這不是廣告)。

  想定,我把同步關閉,問題好像真的就解決了。但詭異的是之前打開同步的時候明明是顯示同步完成了的狀態。為什么還會有文件沖突?難不成是群暉對我“隱瞞了什么”?不得而知。但總不能為了這個而不同步吧。繼續找碴,最終發現解決問題的關鍵在這:


由原來的在服務器上保留版本改成保留最新修改的版本后問題解決

但是,但是,為什么同樣的情況,win7下不會出這問題?我的答案是,win7時我是把文件放在ssd盤上做同步的,win10是放在普通HD硬盤,可能跟這個速度有關。姑且這么想吧。雖然沒有真正發現問題的原因,但問題總算被“完美”解決了。

把這個問題發出來,以便有朋友也不小心掉進類似的坑。遇到這樣的問題,第一時間要排查是不是有什么進程對目標文件進行了鎖定之類的限制。

如果你有更好的答案,懇請不吝賜教。

夜深不及校對文字,有誤之處還請見諒!

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容