How to delete a file from the file system based on the returned case-insensitive delta?

I am trying to write code to execute this particular case documented in the python SDK for the Dropbox Core API.

[path, zero]: indicates that there is no file / folder on the path to Dropbox. To update the local state for compliance, delete everything that is in the way, including any children (sometimes you can also get delta β€œdelete” records for children, but this is not guaranteed). If your local state has nothing in the way, ignore this entry.

The API notes that the returned [path] not case sensitive.

Remember: Dropbox handles file names in a case-insensitive but case-sensitive manner. To facilitate this, the above path lines are versions of the actual bottom-base path. The dicts metadata has an original, case-saved path.

How to delete the file or directory in question from my system if I do not know the version saved in the case of the path?

If relevant, my operating system is on Linux, although I hope to get a solution that will work on Windows, if at all possible.

+4
source share
2 answers

If you need to restore the path with the original case (for example, for your local case-sensitive file system) from the lower circled path, one solution is to keep the display of the omitted path to the original client of the path side. The specific implementation details are up to you, but any simple store of key values ​​is likely to do the job.

Then, when you receive one of these deletions, you can use this mapping to find the source path and process it accordingly.

+1
source

I know this is a little late, but I just stumbled upon the same problem and came up with a different solution. Perhaps someone looking at this will prefer this method.

Since my API was used exclusively on a Linux server, and since removal would be a relatively rare occurrence for me, I depended on the find linux command to help me.

  # LINUX ONLY cmd = "find {0} -iwholename '{1}'".format(basepath, caseInsensitivePath) with os.popen(cmd) as f: caseSensitivePath = f.read()[:-1] # -1 to remove the '\n' # error if more than 1 line if caseSensitivePath.find('\n') != -1: print "Found multiple results including: \n", caseSensitivePath msg = "[!]ERROR Could not delete {0}. Multiple case-sensitive results exist".format(caseInsensitivePath) raise Exception(msg) else: return caseSensitivePath 

basepath is the base search path. I would recommend finding a way to use something more precise than root '/'. In my case, I already had a list of paths in the synchronization folder, so I was able to perform the comparison as follows:

 caseInsensitivePath = caseInsensitivePath.lower() # find basepath basepath = assets_root for folder in self.myDict.keys(): if caseInsensitivePath.lower().startswith(folder.lower()): basepath = folder 

caseInsensitivePath is the way to go.

+1
source

Source: https://habr.com/ru/post/1501600/


All Articles