4

For an application I want to read Google Chrome's cache files. The problem is when Chrome is running the files are opened and may be updated by its process.

So when I tried

data_1 = open("C:\Users\user\AppData\Local\Google\Chrome\User Data\Default\Cache\data_1")

it gave me

IOError: [Errno 13] Permission denied: 'C:\\Users\\user\\AppData\\Local\\Google\\Chrome\\User Data\\Default\\Cache\\data_1' .

Since it says Permission denied( EDIT : I have 'full controll' permission on the file) I also tried it on an elevated cmd window. Same happens. It works fine when Chrome is not running. I want something like this (FileShare on .net).

I think Chrome will allow shared read access because I've seen this application doing it.

Edit:

I think I'm wrong. As lulyon said it seems Chrome locks the file. Because I tried it on vb.net like:

Dim d As New FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read)

it says:

The process cannot access the file because it is being used by another process.

Initially I thought ChromeCacheView copies the file to some other location. So I took a deeper look using process monitor. Please check this screenshot. Doesn't that mean both applications are sharing the same files?

Process monitor: Chrome and ChromeCacheView

I don't think there'll be any understanding between both as ChromeCacheView is third party application. So How is it possible then?

Community
  • 1
  • 1
Rahul K
  • 665
  • 10
  • 25

1 Answers1

1

It is likely chrome prevent you from writing to the cache file it is using. Try to make a copy of the cache file(with whatever tools(like cp command) you have at hand), and do the I/O with the replica.

A possible explaination is that when chrome get the permisson for read, write and append access, simply opening the file with read permission, reading the bytes with seek operation behind the scene would mess your own reading content, so to be denied by the OS.

To check read permission before you call the function open with a default read access, with os.stat(filepath).st_mode; to find if you have the read permisson.

Only if it is comfirmed that you have no read permisson, we could go further to figure out why chrome block your access to cache file, but not that of ChromeCacheView.

lulyon
  • 6,707
  • 7
  • 32
  • 49
  • But I don't need write access. If chrome prevents read access too then how apps like ChromeCacheView do that? – Rahul K Jul 20 '13 at 07:41
  • @rahul So we have to figure out what "Permission denied" means. Reply to you later. – lulyon Jul 20 '13 at 07:45
  • @rahul Is it because your current user do not have access permission to the folder that contains your cache file, or your cache file is not readable to your current user? check it. – lulyon Jul 20 '13 at 07:53
  • No sir, And as I said, I could read the file while chrome is not running – Rahul K Jul 20 '13 at 08:13
  • @rahul Then it is not about whether you need write access. When chrome get the permisson for read, write and append access, simply opening the file with read permission, reading the bytes with seek operation behind the scene would mess your own reading content, so to be denied by the OS. – lulyon Jul 20 '13 at 08:22
  • @rahul Check read permission before you call the function open with a default read access, with os.stat(filepath).st_mode; to find if you have the read permisson. This would explain everything. – lulyon Jul 20 '13 at 08:36
  • @rahul The answer is re-edited just now, which is for you to review. Nice being engaged in this question. I've learned something myself. – lulyon Jul 20 '13 at 08:44
  • os.stat(filepath).st_mode gives 33206. what that means? – Rahul K Jul 20 '13 at 08:47
  • @rahul oct(os.stat(filepath).st_mode)[-3:]; If the result is '666', which is unix-like file access permission bits. It means owner, group, and other user all have the read, write permission(but not the execution permission) to this file. Check it when your chrome is using this file. By the way, do more research before ask instead of empty talks here. Anyway, We are just here to help(with no more clue than you give us), it is up to you to solve the problem. Whenver you figure out the problem, let me know. – lulyon Jul 20 '13 at 09:17
  • @rahul Good. I've marked your question. I'll review it later. – lulyon Jul 21 '13 at 12:56