mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
it is ICS responsibility to remove ROOT_CONFIG from file path on copy local config
This commit is contained in:
@@ -74,11 +74,11 @@ class ApplicationStorageManager(private val application: Application, pathMacroM
|
||||
}
|
||||
|
||||
override fun getOldStorageSpec(component: Any, componentName: String, operation: StateStorageOperation): String? {
|
||||
if (component is NamedJDOMExternalizable) {
|
||||
return "${component.externalFileName}${FileStorageCoreUtil.DEFAULT_EXT}"
|
||||
return if (component is NamedJDOMExternalizable) {
|
||||
"${component.externalFileName}${FileStorageCoreUtil.DEFAULT_EXT}"
|
||||
}
|
||||
else {
|
||||
return DEFAULT_STORAGE_SPEC
|
||||
DEFAULT_STORAGE_SPEC
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,20 +103,12 @@ class ApplicationStorageManager(private val application: Application, pathMacroM
|
||||
}
|
||||
}
|
||||
|
||||
override fun normalizeFileSpec(fileSpec: String): String {
|
||||
var path = super.normalizeFileSpec(fileSpec)
|
||||
if (path.startsWithMacro(StoragePathMacros.APP_CONFIG)) {
|
||||
return path.substring(StoragePathMacros.APP_CONFIG.length + 1)
|
||||
}
|
||||
return path
|
||||
}
|
||||
override fun normalizeFileSpec(fileSpec: String) = removeMacroIfStartsWith(super.normalizeFileSpec(fileSpec), StoragePathMacros.APP_CONFIG)
|
||||
|
||||
override fun expandMacros(path: String): String {
|
||||
if (path[0] == '$') {
|
||||
return super.expandMacros(path)
|
||||
}
|
||||
else {
|
||||
return "${expandMacro(StoragePathMacros.APP_CONFIG)}/$path"
|
||||
}
|
||||
override fun expandMacros(path: String) = if (path[0] == '$') {
|
||||
super.expandMacros(path)
|
||||
}
|
||||
else {
|
||||
"${expandMacro(StoragePathMacros.APP_CONFIG)}/$path"
|
||||
}
|
||||
}
|
||||
@@ -27,13 +27,7 @@ class ProjectStateStorageManager(macroSubstitutor: TrackingPathMacroSubstitutor,
|
||||
val VERSION_OPTION = "version"
|
||||
}
|
||||
|
||||
override fun normalizeFileSpec(fileSpec: String): String {
|
||||
var path = super.normalizeFileSpec(fileSpec)
|
||||
if (path.startsWithMacro(StoragePathMacros.PROJECT_CONFIG_DIR)) {
|
||||
return path.substring(StoragePathMacros.PROJECT_CONFIG_DIR.length + 1)
|
||||
}
|
||||
return path
|
||||
}
|
||||
override fun normalizeFileSpec(fileSpec: String) = removeMacroIfStartsWith(super.normalizeFileSpec(fileSpec), StoragePathMacros.PROJECT_CONFIG_DIR)
|
||||
|
||||
override fun expandMacros(path: String): String {
|
||||
if (path[0] == '$') {
|
||||
|
||||
@@ -384,7 +384,7 @@ open class StateStorageManagerImpl(private val rootTagName: String,
|
||||
}
|
||||
}
|
||||
|
||||
override fun getOldStorage(component: Any, componentName: String, operation: StateStorageOperation): StateStorage? {
|
||||
override final fun getOldStorage(component: Any, componentName: String, operation: StateStorageOperation): StateStorage? {
|
||||
val oldStorageSpec = getOldStorageSpec(component, componentName, operation) ?: return null
|
||||
@Suppress("DEPRECATION")
|
||||
return getOrCreateStorage(oldStorageSpec, if (component is com.intellij.openapi.util.RoamingTypeDisabled) RoamingType.DISABLED else RoamingType.DEFAULT)
|
||||
@@ -393,7 +393,9 @@ open class StateStorageManagerImpl(private val rootTagName: String,
|
||||
protected open fun getOldStorageSpec(component: Any, componentName: String, operation: StateStorageOperation): String? = null
|
||||
}
|
||||
|
||||
fun String.startsWithMacro(macro: String): Boolean {
|
||||
private fun String.startsWithMacro(macro: String): Boolean {
|
||||
val i = macro.length
|
||||
return length > i && this[i] == '/' && startsWith(macro)
|
||||
}
|
||||
}
|
||||
|
||||
fun removeMacroIfStartsWith(path: String, macro: String) = if (path.startsWithMacro(macro)) path.substring(macro.length + 1) else path
|
||||
@@ -17,6 +17,7 @@ package org.jetbrains.settingsRepository
|
||||
|
||||
import com.intellij.configurationStore.ROOT_CONFIG
|
||||
import com.intellij.configurationStore.StateStorageManagerImpl
|
||||
import com.intellij.configurationStore.removeMacroIfStartsWith
|
||||
import com.intellij.ide.actions.ExportableItem
|
||||
import com.intellij.ide.actions.getExportableComponentsMap
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
@@ -30,22 +31,21 @@ fun copyLocalConfig(storageManager: StateStorageManagerImpl = ApplicationManager
|
||||
val streamProvider = storageManager.streamProvider!! as IcsManager.IcsStreamProvider
|
||||
|
||||
val fileToComponents = getExportableComponentsMap(true, false, storageManager)
|
||||
for (file in fileToComponents.keySet()) {
|
||||
for (file in fileToComponents.keys) {
|
||||
val absolutePath = FileUtilRt.toSystemIndependentName(file.absolutePath)
|
||||
var fileSpec = storageManager.collapseMacros(absolutePath)
|
||||
LOG.assertTrue(!fileSpec.contains(ROOT_CONFIG))
|
||||
if (fileSpec.equals(absolutePath)) {
|
||||
var fileSpec = removeMacroIfStartsWith(storageManager.collapseMacros(absolutePath), ROOT_CONFIG)
|
||||
if (fileSpec == absolutePath) {
|
||||
// we have not experienced such problem yet, but we are just aware
|
||||
val canonicalPath = FileUtilRt.toSystemIndependentName(file.canonicalPath)
|
||||
if (!canonicalPath.equals(absolutePath)) {
|
||||
fileSpec = storageManager.collapseMacros(canonicalPath)
|
||||
if (canonicalPath != absolutePath) {
|
||||
fileSpec = removeMacroIfStartsWith(storageManager.collapseMacros(canonicalPath), ROOT_CONFIG)
|
||||
}
|
||||
}
|
||||
|
||||
val roamingType = getRoamingType(fileToComponents.get(file)!!)
|
||||
if (file.isFile) {
|
||||
val fileBytes = FileUtil.loadFileBytes(file)
|
||||
streamProvider.doSave(fileSpec, fileBytes, fileBytes.size(), roamingType)
|
||||
streamProvider.doSave(fileSpec, fileBytes, fileBytes.size, roamingType)
|
||||
}
|
||||
else {
|
||||
saveDirectory(file, fileSpec, roamingType, streamProvider)
|
||||
@@ -54,13 +54,12 @@ fun copyLocalConfig(storageManager: StateStorageManagerImpl = ApplicationManager
|
||||
}
|
||||
|
||||
private fun saveDirectory(parent: File, parentFileSpec: String, roamingType: RoamingType, streamProvider: IcsManager.IcsStreamProvider) {
|
||||
val files = parent.listFiles()
|
||||
if (files != null) {
|
||||
for (file in files) {
|
||||
val childFileSpec = parentFileSpec + '/' + file.name
|
||||
parent.listFiles()?.let {
|
||||
for (file in it) {
|
||||
val childFileSpec = "$parentFileSpec/${file.name}"
|
||||
if (file.isFile) {
|
||||
val fileBytes = FileUtil.loadFileBytes(file)
|
||||
streamProvider.doSave(childFileSpec, fileBytes, fileBytes.size(), roamingType)
|
||||
streamProvider.doSave(childFileSpec, fileBytes, fileBytes.size, roamingType)
|
||||
}
|
||||
else {
|
||||
saveDirectory(file, childFileSpec, roamingType, streamProvider)
|
||||
|
||||
Reference in New Issue
Block a user