How to set properties for nodes along a path

I want to set a common property for all nodes in a single path.

I have a file dependency chain - (file)-[DEPENDS_ON*0..]->(file)

I want to calculate the length of each dependency path and set that length as a property for all nodes in that path. Here is my query -

match p=(f:FileName)-[r:DEPENDENT_ON*1..30]->(f1:FileName)
with p, length(p) as length, (nodes(p)) as nodes limit 10
unwind nodes as node
set = length
return *

But the problem is certain nodes in a path do not get set with same property value of the path length.

Could it be that different paths cross the same node and overwrite a previous value?